mysql restart from cron using shell script

check crontab -u root -l - list of cron for user root
cd /home/smruti/
sudo nano mysql-check.sh
==========================================================
#!/bin/bash
/usr/bin/mysqladmin ping| grep 'mysqld is alive' > /dev/null 2>&1
if [ $? != 0 ]
then
    sudo service mysqld restart
fi
======================================
save as  mysql-check.sh
To make it executable chmod 0755 mysql-check.sh
create cron job  crontab -e from command 
type * * * * * sh -x /home/smruti/mysql-check.sh
press esc :wq for save

check it by type sudo service mysqld stop
it will automatically start after 1 min.

Leave a Reply

Your email address will not be published. Required fields are marked *