获取从库Seconds_Behind_Master监控主从同步

时间:2022-02-26 09:43:44
#!/bin/bash

now_date=`date "+%Y-%m-%d,%H:%M:%S"`
flag_old=`cat /home/oracle/scripts/flag.txt|cut -d '|' -f `
flag_new=`mysql -P3306 -hlocalhost -uroot -ptestpwd -D mysql -e "show slave status\G" >/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 "$msg"
fi if [ "$flag_new" -ge ]; then
msg="从库同步behind_master=$flag_new,同步正常,检查时间:${now_date}"
/home/oracle/scripts/senddingd "$msg"
fi fi
echo "$flag_new|$now_date">/home/oracle/scripts/flag.txt