```bash #!/usr/bin/env bash #================================================================ # # systemos=centos7.2 # #this is mysql backups scripts # Author:xw thank you!!! # Date:2018.11.21 # Description:supervisory control mysql Master-slave # wang.cong@aliyun.com #================================================================ mycmd="mysql -uroot -p123456 -S /data/3306/mysql.sock" error=(1158 1159 1008 1007 1062) status=($($mycmd -e "show slave status\G"|egrep "Seconds_Behind|_Running|Last_SQL_Errno"|awk '{print $NF}')) check(){ if [ "${status[0]}" = "yes" -a "${status[1]}" = "yes" -a "${status[2]}" = "0" ];then echo "the mysql_slave is ok" stu=0 return $stu else stu=1 return $stu fi } check_error(){ check if [ $? -eq 1 ];then for n in ${error[*]} do if [ "${status[3]}" = "$n" ];then $mycmd -e "stop slave;" $mycmd -e "set global sql_slave_skip_counter = 1" $mycmd -e "start slave;" fi done fi } check_again(){ status="(`$mycmd -e "show slave status\G"|grep -E "Seconds_Behind_Master|_Running|Last_SQL_Errno"|awk '{print $2}'`)" if [ $? -eq 1 ];then echo "mysql is fail `date +%F_$T`" >/tmp/a.log mail -s "mysql is fail `date +%F_$T`" 123@qq.com