检测MySQL是否宕机并重启
检测MySQL是否宕机并重启,建立脚本添加到crontab
中
#!/bin/bash
result=`/usr/bin/mysqladmin ping`
expected='mysqld is alive'
if [[ "$result" != "$expected" ]]
then
echo "It's dead - restart mysql"
# email subject
SUBJECT="[MYSQL ERROR] - Attempting to restart service"
# Email To ?
EMAIL="info@endyourif.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
在crontab
中5分钟检测一次
*/5 * * * * /<path_to>/scripts/mysql.sh
原文出自http://www.codeproject.com/Articles/988967/Mysql-Uptime-Check-Script
- 上一篇: JavaScript黑魔法jother编码之谜
- 下一篇: 模拟易名中国域名的点赞