监控slave的脚本(即监控主从mysql同步的脚本):
# vi slave.sh
#!/bin/bash
IO_env=`/usr/local/mysql/bin/mysql -u root -p123456 -e "show slave status \G" | grep Slave_IO_Running | awk -F[:" "]+ '{print $3}'`
SQL_env=`/usr/local/mysql/bin/mysql -u root -p123456 -e "show slave status \G" | grep Slave_SQL_Running | awk -F[:" "]+ '{print $3}'`
if [ $IO_env == "Yes" -a $SQL_env == "Yes" ];then
echo "slave is running at time:`date +%y/%m/%d-%H:%M`" >> /usr/local/mysql/logs/mysqllog/slave.log
else
echo "slave is down at time:`date +%y/%m/%d-%H:%M`" >> /usr/local/mysql/logs/mysqllog/slave.log
fi
SQL_env=`/usr/local/mysql/bin/mysql -u root -p123456 -e "show slave status \G" | grep Slave_SQL_Running | awk -F[:" "]+ '{print $3}'`
if [ $IO_env == "Yes" -a $SQL_env == "Yes" ];then
echo "slave is running at time:`date +%y/%m/%d-%H:%M`" >> /usr/local/mysql/logs/mysqllog/slave.log
else
echo "slave is down at time:`date +%y/%m/%d-%H:%M`" >> /usr/local/mysql/logs/mysqllog/slave.log
fi
:wq
本文转自linux博客51CTO博客,原文链接http://blog.51cto.com/yangzhiming/836378如需转载请自行联系原作者
yangzhimingg