获取从库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 statusG" 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

原文地址:https://www.cnblogs.com/hxlasky/p/10314350.html