首页 > 代码库 > Mysql 主从复制监控脚本

Mysql 主从复制监控脚本

Mysql 主从复制监控脚本,
监控IO和SQL线程。如果问题。发送邮件报警。



#!/bin/bash
#write by lijun
#Date 2014-08-12
#Description monitor the master pass the data to the slave
#=====================
mail="邮件地址"

#===================

#获取slave io 进程和sql进程的状态

b="`mysql -uroot -p$a -e "show slave status\G;"|grep -E ‘Slave_IO_Running|Slave_SQL_Running‘|awk -F: ‘{print $2}‘|grep -v ‘^$‘`"

#判断两个进程是否开启

if [ b == "yes" ]
    then
        echo "IO thread and SQL thread are ‘yes‘"
    else
        yum install mail* -y  &>>/dev/null
        /etc/init.d/httpd restart
        echo
        echo "`date +%F-%T`主从复制错误,请进行检查."|mail -s "IO and SQL are wrong" $mail
        echo
     if [ $? -eq 0 ]
         then
             echo "send mail ok"
         else
             echo "send mail failed..."
             echo
     fi
fi