1. [root@A 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) 10. MySQL_CMD="mysql -uroot -p888888 -S /data/3308/mysql.sock" 11. while true 12. do 13. 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" ];then 15. echo"MySQL salve status is OK." 16. else 17. for ((i=0; i<${#ERRORNO[*]}; i++)) 18. do 19. if [ "${array[3]}"== "${ERRORNO[$i]}" ];then 20. $MySQL_CMD-e "stop slave;set globalsql_slave_skip_counter=1;start slave;" 21. fi 22. done 23. chars="MySQL salve status is FAIED." 24. echo"$chars" 25. echo"$chars"|mail -s "$chars" 813415154@qq.com 26. fi 27. sleep 3 28. done
转载于:https://blog.51cto.com/zhagyilig/1852694