本文共 1257 字,大约阅读时间需要 4 分钟。
1. [root@A mysql]# cat check_slave_status.sh 2. #!/bin/sh3. #--------------------------------------------4. #Author: Created by randolph 2016-08-17.5. #Function: This scripts function is"Monitoring MySQL Master-Slave Status".6. #Version:4.1.27. #---------------------------------------------8. 9. ERRORNO=(1158 1158 1008 1007 1062)10. MySQL_CMD="mysql -uroot -p888888 -S /data/3308/mysql.sock"11. while true12. do13. array=($($MySQL_CMD-e "show slave status\G"|egrep"Running|Behind_Master|Last_SQL_Errno"|awk-F ":" '{print $NF}'))14. if [ "${array[0]}"== "Yes" -a "${array[1]}" == "Yes" -a "${array[2]}"== "0" ];then15. echo"MySQL salve status is OK."16. else17. for ((i=0; i<${#ERRORNO[*]}; i++))18. do19. if [ "${array[3]}"== "${ERRORNO[$i]}" ];then 20. $MySQL_CMD-e "stop slave;set globalsql_slave_skip_counter=1;start slave;"21. fi22. done23. chars="MySQL salve status is FAIED."24. echo"$chars"25. echo"$chars"|mail -s "$chars" 813415154@qq.com26. fi27. sleep 328. done
转载于:https://blog.51cto.com/zhagyilig/1852694