1. 程式人生 > >MySQL主從複製郵件報警指令碼

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"

[email protected]"
fi