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

#!/bin/bash

##author:jerry_jiang

mail_addr="username@163.com" 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