圆月山庄资源网 Design By www.vgjia.com

此脚本首先判断mysql服务器是否运行,如果正常,继续判断主从,否则发邮件告警,只发一次。
判断主从状态是判断IO和SQL线程是否都为yes,如果不是则发邮件通知,只发一次。

复制代码 代码如下:
#!/bin/bash
#define mysql variable
mysql_user="root"
mysql_pass="123456"
email_addr="slave@jb51.net"

mysql_status=`netstat -nl | awk 'NR>2{if ($4 ~ /.*:3306/) {print "Yes";exit 0}}'`
if [ "$mysql_status" == "Yes" ];then
        slave_status=`mysql -u${mysql_user} -p${mysql_pass} -e"show slave status\G" | grep "Running" | awk '{if ($2 != "Yes") {print "No";exit 1}}'`
        if [ "$slave_status" == "No" ];then
                echo "slave is not working!"
                [ ! -f "/tmp/slave" ] && echo "Slave is not working!" | mail -s "Warn!MySQL Slave is not working" ${email_addr}
                touch /tmp/slave
        else
                echo "slave is working."
                [ -f "/tmp/slave" ] && rm -f /tmp/slave
        fi
        [ -f "/tmp/mysql_down" ] && rm -f /tmp/mysql_down
else
        [ ! -f "/tmp/mysql_down" ] && echo "Mysql Server is down!" | mail -s "Warn!MySQL server is down!" ${email_addr}
        touch /tmp/mysql_down
fi

标签:
shell脚本,监控mysql

圆月山庄资源网 Design By www.vgjia.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
圆月山庄资源网 Design By www.vgjia.com