#!/bin/bash
mysql_cmd="mysql -uroot -p1234567 -S /tmp/mysql.sock"
errorno=(1158 1159 1008 1007 1062)
#数值定义错误号 这些错误号要跳过
while true;do
array=(`$mysql_cmd -e ("show slave status\G" | egrep '
_Running:|Seconds_Behind|Last_SQL_Errno' |awk '{print $NF}'
)`)
if [ ${array[0]} = "Yes" ] && [ ${array[1]} = "Yes" ] && [ ${array[2]} = "0" ]; then
echo "mysql slave is ok"
else
for(( i=0; i<${#errorno[$i]}; i++ )); do
if [ ${array[3]} = "${errorno[$i]}" ]; then
$mysql_cmd -e "stop slave;set global sql_slave_skip_counter=1;start slave;"
fi
done
char= "mysql slave is not ok"
echo "$char"
echo "$char" | mail -s "$char" xxxx@qq.com
fi
sleep 30
done