获取从库Seconds_Behind_Master监控主从同步

 

#!/bin/bash

now_date=`date "+%Y-%m-%d,%H:%M:%S"` 
flag_old=`cat /home/oracle/scripts/flag.txt|cut -d '|' -f 1`
flag_new=`mysql -P3306 -hlocalhost -uroot -ptestpwd -D mysql -e "show slave status\G" 2>/dev/null|grep Seconds_Behind_Master|sed s/[[:space:]]//g|cut -f 2 -d ":"`
if [ "$flag_old" != "$flag_new" ]; then
 if [ "$flag_new" = "NULL" ]; then
 msg="从库异常behind_master=$flag_new,同步异常,检查时间:${now_date}"
 /home/oracle/scripts/senddingd 13800000 "$msg"
 fi

 if [ "$flag_new" -ge 0 ]; then
 msg="从库同步behind_master=$flag_new,同步正常,检查时间:${now_date}"
 /home/oracle/scripts/senddingd 13800000 "$msg"
 fi

fi
echo "$flag_new|$now_date">/home/oracle/scripts/flag.txt

posted @ 2019-01-24 14:35  slnngk  阅读(291)  评论(0编辑  收藏  举报