实现Shell脚本监控MySql主从同步
先上脚本文件
#!/bin/bash #check MySQL_Slave Status #crontab time 00:10 MYSQLIP=`ifconfig eth0|grep "inet addr" | awk -F[:" "]+ ‘{print $4}‘` STATUS=$(mysql -uroot -ppassword -hhost -e "show slave status\G" | grep -i "running") IO_env=`echo $STATUS | grep IO | awk ‘ {print $2}‘` //判断条件一 SQL_env=`echo $STATUS | grep SQL | awk ‘{print $2}‘` //判断条件二 DATA=`date +"%y-%m-%d %H:%M:%S"` if [ "$IO_env" = "Yes" -a "$SQL_env" = "Yes" ] then echo "Slave is running!" else echo "####### $DATA #########">> /check_mysql_slave.log echo "Slave is not running!" >> /check_mysql_slave.log echo "Slave is not running!" | mail -s "warn! $MYSQLIP MySQL Slave is not running" fi
slave status
逻辑:通过判断Salve_IO_Running 和 Salve_SQL_Running 这两个参数值是否都是 Yes 来实现监控主从数据库,如果其中一个参数值不是Yes则需要邮件通知。
注意 :对于不能在Linux下成功发送邮件的需要接着完成下面的步骤
测试是否能成功邮件发送代码
mail -s " mail is running"
如果报错 mail not command 就需要在Linux里安装mail了
可以参考一下这篇文章 https://blog.espnlol.com/?p=335(这里的配置的是腾讯企业邮箱smtps 45端口)
相关推荐
tufeiax 2020-09-03
彼岸随笔 2020-10-20
yutou0 2020-10-17
jarrygao 2020-11-02
shipinsky 2020-09-23
touchfuture 2020-09-16
hongsheyoumo 2020-09-04
tianhuak 2020-11-24
huha 2020-10-16
lianshaohua 2020-09-23
laisean 2020-11-11
zhangjie 2020-11-11
大牛牛 2020-10-30
firefaith 2020-10-30
liguojia 2020-10-20
wangzhaotongalex 2020-10-20
以梦为马不负韶华 2020-10-20
CARBON 2020-10-20
lianshaohua 2020-10-20