#!/bin/bash # check mysql slave status USER="check" PSW="***" RUNTIME=3600 ADDR="192.168.*.*" declare -a slave_is for IP in $ADDR do slave_is=($(/usr/local/mysql/bin/mysql -h$IP -u${USER} -p${PSW} -e "show slave status\G"|grep Running|awk ‘{print $2}‘)) if [ "${slave_is[0]}" = "Yes" -a "${slave_is[1]}" = "Yes" ] then echo -e "${IP} - Slave Status: \e[1;32m [ OK ] \e[0m" > /app/sqlstatus else echo "${IP} - Slave Status: \e[1;31m [ ERROR ] \e[0m" > /app/sqlstatus cat "/app/sqlstatus" |mutt -s "mysql slave" your_mail@163.com fi sleep $RUNTIME done
间隔一小时检查一次,如果出错,发送邮件
本文出自 “一颗石头 BBOTTE的博客” 博客,请务必保留此出处http://bbotte.blog.51cto.com/6205307/1410008
原文:http://bbotte.blog.51cto.com/6205307/1410008