mysql主从检测脚本

时间:2014-05-13 04:33:44   收藏:0   阅读:374
#!/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

bubuko.com,布布扣

间隔一小时检查一次,如果出错,发送邮件

本文出自 “一颗石头 BBOTTE的博客” 博客,请务必保留此出处http://bbotte.blog.51cto.com/6205307/1410008

mysql主从检测脚本,布布扣,bubuko.com

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!