监控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
:wq