Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
MYSQL_RUNNING=0
function checkMysql {
/usr/sbin/service mysql status | grep Uptime
if [ "$?" == 0 ]; then
MYSQL_RUNNING=1
fi
}
checkMysql
if [ "$MYSQL_RUNNING" == 0 ]; then
echo 'MySQL is down'
/usr/sbin/service mysql start
checkMysql
if [ -a /root/.mysql-monitor ]; then
if [ "$MYSQL_RUNNING" == 0 ]; then
echo 'MySQL is down and failed to be restarted' | mail steve@steverobbins.com -s 'Prince Lion Heart MySQL has stopped'
else
echo 'MySQL is down but was restarted successfully' | mail steve@steverobbins.com -s 'Prince Lion Heart MySQL has stopped'
fi
rm -rf /root/.mysql-monitor
fi
else
echo 'MySQL is up'
date > /root/.mysql-monitor
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment