master上设置定时任务:

#!/bin/sh
if [ -f /root/mysql_slave_status.txt ]
  then
    rm -f /root/mysql_slave_status.txt
    mysql -uroot -pxxxxxx -e "show slave status\G" |egrep "_Running:|Behind_Master"|awk '{print $2}' >/root/mysql_slave_status.txt
    array=($(cat /root/mysql_slave_status.txt |xargs))
    if [ "${array[0]}" == "Yes" -a "${array[1]}" == "Yes" -a "${array[2]}" == "0" ]
      then
         echo "mysql slave is ok"``
      else
         char="mysql slave is not ok"
         sleep 3
         echo "$char"|mail -s "xxxxx mysql_slave is error" [email protected]
    fi
fi