mysql主从同步监控小脚本
 
可以将其结合nagios监控,用来做监控报警:

  1. #!/bin/sh
  2. #file is slave_repl.sh
  3. #Author by Kevin
  4. #date is 2011-11-13
  5. declare -a slave_stat
  6. slave_stat=($(/apps/usr/mysql-3307/bin/mysql -h slave_hostname -uroot -p123456 -P 3307 -e "show slave status\G"|grep Running |awk '{print $2}'))
  7. if [ "${slave_stat[0]}" = "Yes" -a "${slave_stat[1]}" = "Yes" ]
  8. then
  9. echo "OK slave is running"
  10. exit 0
  11. else
  12. echo "Critical slave is error"
  13. exit 2
  14. fi