Tuesday, July 30, 2024

IBM DB2 STOP and START

 #!/bin/bash

# Function to stop Db2
stop_db2() {
echo “Stopping Db2…”
db2stop
if [ $? -eq 0 ]; then
echo “Db2 stopped successfully.”
else
echo “Regular stop failed. Attempting forceful stop…”
db2stop force
if [ $? -eq 0 ]; then
echo “Db2 stopped forcefully.”
else
echo “Failed to stop Db2.”
fi
fi
}

# Function to start Db2
start_db2() {
echo “Starting Db2…”
db2start
if [ $? -eq 0 ]; then
echo “Db2 started successfully.”
else
echo “Failed to start Db2.”
fi
}

# Main script
if [ “$1” == “stop” ]; then
stop_db2
elif [ “$1” == “start” ]; then
start_db2
else
echo “Usage: $0 [stop|start]”
exit 1
fi