运维开发网

shell监控mysql主从是否正常

运维开发网 https://www.qedev.com 2020-01-30 14:26 出处:网络 作者:doubf
#!/bin/shif[-f/root/mysql_slave_status.txt]thenrm-f/root/mysql_slave_status.txtmysql-uroot-pxxxxxx-e"showslavestatus\G"|egrep"_Running:|Behind_Master"|awk'{print$2}'>/root/mysql_slave_status.txtarr

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" 111111111@qq.com
    fi
fi
0

精彩评论

暂无评论...
验证码 换一张
取 消