1. [email protected] mysql]# cat check_slave_status.sh
2. #!/bin/sh
3. #--------------------------------------------
4. #Author: Created by Randolph 2016-08-17.
5. #Function: This scripts Function is "monitoring MySQL master-slave Status".
6. #Version: 4.1.2
7. #---------------------------------------------
8.
9. errorno= (1158 1158 1008 1007 1062)
. mysql_cmd= "mysql-uroot-p888888-s/data/3308/mysql.sock"
One by one . while true
. Do
13. array= ($ ($MySQL _cmd-e " show Slave Status\g "|egrep" running| behind_master| Last_sql_errno "|awk-f" : "' {print $NF} ')
. if ["${array[0]}" = = "Yes"-a "${array[1]}" = = "Yes"-a "${array[ 2]}"= ="0"];then
A . echo "MySQL salve status is OK."
. Else
. For ((i=0; i<${#ERRORNO [*]}; i++))
. do
. if ["${array[3]}" = = "${errorno[$i]}"];then
. $MySQL _cmd-e "stop slave;set globalsql_slave_skip_counter=1;start slave;"
. fi
. Done
. chars= "MySQL salve status is faied."
A . echo "$chars"
. echo "$chars" |mail-s "$chars" [email protected]
. fi
. Sleep 3
. Done
This article from "Randolph" blog, reproduced please contact the author!
Monitor MySQL master-slave synchronization status