码迷,mamicode.com
首页 > 数据库 > 详细

一分钟教你快速建立起MySQL/Mariadb 主从状态检测脚本(shell)

时间:2018-09-28 14:36:04      阅读:202      评论:0      收藏:0      [点我收藏+]

标签:pass   ==   ima   stat   3.1   server   erro   amp   gre   

脚本主要实现了网络检测和简单的主从状态检测,发现状态异常即发送邮件报警,在手机上安装一个易信可实现实时联动,及时获取服务器状态信息,脚本虽简单却实用。

#!/bin/bash

##author:jerry_jiang

mail_addr="username@163.com"br/>mail_addr2="username@163.com"
ping 192.168.33.19 -c1 >/dev/null
sping1=echo $?
ping 192.168.33.20 -c1 >/dev/null
sping2=echo $?
if [ $sping1 == 0 ]; then
status19=mysql -uuser -ppassword -h192.168.33.19 -P33060 -e "show slave status\G;"|grep Yes|wc -l
[ $status19 != 2 ] && echo "Master and slave error,Check it,Server IP:192.168.17.19"|mailx -v -s "master and slave warnning" $mail_addr
[ $status19 != 2 ] && echo "Master and slave error,Check it,Server IP:192.168.17.19"|mailx -v -s "master and slave warnning" $mail_addr2
else
echo "Check network,OA Server IP:192.168.17.19"|mailx -v -s "net warnning" $mail_addr
echo "Check network,OA Server IP:192.168.17.19"|mailx -v -s "net warnning" $mail_addr2
fi
if [ $sping2 == 0 ]; then
status20=mysql -uuser -ppassword -h192.168.33.20 -P33060 -e "show slave status\G;"|grep Yes|wc -l
[ $status20 != 2 ] && echo "Master and slave error,Check it,Server IP:192.168.17.20"|mailx -v -s "master and slave warnning" $mail_addr
[ $status20 != 2 ] && echo "Master and slave error,Check it,Server IP:192.168.17.20"|mailx -v -s "master and slave warnning" $mail_addr2
else
echo "Check network,OA Server IP:192.168.17.20"|mailx -v -s "net warnning" $mail_addr
echo "Check network,OA Server IP:192.168.17.20"|mailx -v -s "net warnning" $mail_addr2
fi

技术分享图片

一分钟教你快速建立起MySQL/Mariadb 主从状态检测脚本(shell)

标签:pass   ==   ima   stat   3.1   server   erro   amp   gre   

原文地址:http://blog.51cto.com/jdonghong/2287109

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!