ITPub博客

首页 > Linux操作系统 > Linux操作系统 > mysql监控脚本

mysql监控脚本

原创 Linux操作系统 作者:破棉袄 时间:2015-05-11 11:26:03 0 删除 编辑
监控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/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2014-07-16

  • 博文量
    180
  • 访问量
    1158149