监控mysql服务状态,如果未运行则通知并重启,可加入定时任务中
#!/bin/bash
result=`/usr/bin/mysqladmin -u root -ppassword ping`
expected='mysqld is alive'
if [[ "$result" != "$expected" ]]
then
echo "mysql Not running"
# email subject
SUBJECT="[MYSQL ERROR] - Attempting to restart service"
# Email To ?
EMAIL="tongzhi@tom.com"
# Email text/message
EMAILMESSAGE="/tmp/emailmessage.txt"
echo "$result was received"> $EMAILMESSAGE
echo "when we were expected $expected" >>$EMAILMESSAGE
# send an email using /bin/mail
mail -s "$SUBJECT" "$EMAIL" < $EMAILMESSAGE
sudo /etc/init.d/mysql restart
fi
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/29754888/viewspace-1647702/
,如需转载,请注明出处,否则将追究法律责任。