MySQL主从复制邮件报警脚本

#!/bin/sh
export PATH=$PATH:/application/mysql/3306/bin
logFile=`date +"%Y-%m-%d %H:%M:%S"`_check_mysql_slave.log
mysql='/application/mysql/3306/bin/mysql -uroot -p123456 -S /data1/mysql.data.d/3306/tmp/mysql.sock'
$mysql -e  "show slave status \G;" > tmp.log
IO_env=`cat tmp.log | grep -w Slave_IO_Running | awk '{print $2}'`
SQL_env=`cat tmp.log | grep -w Slave_SQL_Running | awk '{print $2}'`
#判断Slave_IO_Running Slave_SQL_Running状态
if [ "$IO_env" = "Yes" -a "$SQL_env" = "Yes" ]
then
  echo "slave OK!" >> $logFile
else
  echo "replication thread is abnormal" | mail -s "repl log" abc@qq.com"
fi

posted @ 2018-12-05 11:22  Manger  阅读(261)  评论(0编辑  收藏  举报