Shell script issue: cron job script to Restart MySQL server when it stops accidentally
- by Straw Hat
I have this script, I am using it to setup CRON job to execute this script, so it can check if MySQL service is running; if not then it restart the MySQL service:
#!/bin/bash
service mysql status| grep 'mysql start/running' > /dev/null 2>&1
if [ $? != 0 ]
then
sudo service mysql restart
fi
I have setup cron job as.
sudo crontab -e
and then added,
*/1 * * * * /home/ubuntu/mysql-check.sh
Problem is that it restart MySQL on every cron job execution..
even if server is running it restart the MySQL service
what is correction in the script to do that.