Detects MYSLQ from library status, skips fixed error numbers, detects every 30 seconds, automatically skips if eligible, or restarts from library
1) Remove MySQL from the library keyword
1 [[email protected] scripts]# mysql-u root-p123qq.com3307-s/data/3307"show slave stat Us\g"| grep " running| seconds_behind_master| Last_sql_errno"| awk ' {print $NF} ' 2 Yes 3 Yes 4 0 5 0
2) define the error number in the array
3) while Ture
Debug the following script according to your thoughts
1 [email protected] scripts]# cat check_mysql_slave.sh2#/bin/Bash3 #Date:4 #Author:5#Mail:917667797@qq. com6#Function: This scripts Function isCheck MySQL slave isOK7#Version:1.18qq="[email protected]"9Cmd="mysql-u root-p123qq.com3307-s/data/3307/mysql.sock-e"TenIp= ' Ifconfig eth2|sed-n's#^.*ddr:\ (. *\) BC.*$#\1#GP'` OneSkip= ' $cmd"Stop Slave;set global sql_slave_skip_counter=1;start slave;"` AError_numb= (1158 1159 1008 1007 1062) - while true - Do theStatus= (' $cmd"Show Slave Status\g"|grep-e"running| seconds_behind_master| Last_sql_errno"|awk'{print $NF}'`) - - if["${status[0]}"=="Yes"-A"${status[1]}"=="Yes"-A"${status[2]}"=="0" ] - Then +Echo"MySQL slave is ok" - Else + for((n=0; n<${#error_numb [*]};n++)) A Do at if["${status[3]}"=="${error_numb[n]}"];then - ${skip} - Else -$cmd"stop Slave;start slave;" - fi - Done inEcho"MySQL Salve is not ok" -Echo"${ip} mysql is not ok"|mail-s"MySQL slave error at ' date +%f%t '"$QQ to fi +Sleep3 -Done
The test results are as follows
[Email protected] scripts]# sh check_mysql_slave.sh
MySQL Salve is not ok
MySQL slave is ok
MySQL slave is ok
MySQL slave is ok
MySQL slave is ok
MySQL slave is ok
MySQL slave is ok
MySQL slave is ok
MySQL slave is ok
MySQL slave is ok
MySQL slave is ok
Daemon monitoring for MySQL master-slave server