此脚本首先判断Mysql服务器是否运行,如果正常,继续判断主从,否则发邮件告警,只发一次。判断主从状态是判断io和sql线程是否都为yes,如果不是则发邮件通知,只发一次。 #!/bin/bash#def
此脚本首先判断Mysql服务器是否运行,如果正常,继续判断主从,否则发邮件告警,只发一次。
判断主从状态是判断io和sql线程是否都为yes,如果不是则发邮件通知,只发一次。
#!/bin/bash
#define mysql variable
mysql_user="root"
mysql_pass="123456"
email_addr="slave@gimoo.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 statusG" | 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
--结束END--
本文标题: shell脚本监控mysql主从状态
本文链接: https://lsjlt.com/news/17779.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
2024-10-23
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
2024-10-22
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0