Cronjob script to start DB2
#!/bin/bash
#Check Db2 status
db2status=$(db2pd -dbptnmem | grep -i “db2”)
if [[ -z $db2status ]]; then
echo “Db2 is not running. Restarting…”
db2stop force
db2start
else
echo “Db2 is running.”
fi
Make the script executable by running the following command
chmod +x db2_restart.sh
Create Cronjob for the the same
crontab -e
add the following line to the crontab file
*/5 * * * * /path/to/db2_restart.sh >> /path/to/restart_log.txt 2>&1