My LAMP installation on Ubuntu 18.04 LTS is working fine. But sometimes when MySQL is down it doesn't gets restarted automatically. So i google around and found below the bash script which checks whether mysql is running and will start the service if it is not running. Problem is that when mysql is down i receive the email but mysql is not started. Also, the user running the cron job has sudo access. My cronjob is:
*/5 * * * * sudo bash check_mysql.sh > /dev/null 2>&1
The bash script i used:
#!/bin/bash firstname.lastname@example.org' subject='mysql process down and up' MYSQL_START='sudo /etc/init.d/mysql start' MYSQL='mysqld' PGREP='/usr/bin/pgrep' #check pid $PGREP $MYSQL if [ $? -ne 0 ]; then $MYSQL_START | mail -s "$subject" $email <<< 'Mysql was down and successfully started' fi
Is there anything wrong with the script or the cronjob is wrong?