自动监控从MySQL同步的脚本
2016-07-11 16:55:59   来源:   评论:0 点击:

脚本设计思路:1、此脚本应该能适应各种各样不同的内外网环境,即IP不同的环境;2、让脚本也顺便监控下MySQL是否正常运行;3、Slave机器的IO

脚本设计思路:

1、此脚本应该能适应各种各样不同的内外网环境,即IP不同的环境;

2、让脚本也顺便监控下MySQL是否正常运行;

3、Slave机器的IO和SQL状态都必须为YES,缺一不可,这里用到了多重条件判断-a。

#!/bin/bash

#check MySQL_Slave Status

#crontab time 00:10

Mail-list=

MysqlUser=

MysqlPass=

MYSQLPORT=`netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ '{print $5}'`

MYSQLIP=`ifconfig eth0|grep "inet addr" | awk -F[:" "]+ '{print $4}'`

STATUS=$(/usr/local/mysql/bin/mysql -u $MysqlUser -$MysqlPass -e "show slave status\G" | grep -i "running")

IO_env=`echo $STATUS | grep IO | awk ' {print $2}'`

SQL_env=`echo $STATUS | grep SQL | awk '{print $2}'`

if [ "$MYSQLPORT" == "3306" ]

then

echo "mysql is running"

else

/bin/mail -s "warning!server: $MYSQLIP mysql is down" $Mail-list

fi

if [ "$IO_env" = "Yes" -a "$SQL_env" = "Yes" ]

then

echo "Slave is running!"

else

echo "####### $date #########" >> /tmp/check_mysql_slave.log

echo "Slave is not running!" >> /tmp/check_mysql_slave.log

echo "Slave is not running!"

#mail -s "warn! $MySQLIP_replicate_error" $Mail-list << /tmp/check_mysql_slave.log

echo "`cat /tmp/check_mysql_slave.log`" |mail -s "Warning...slave is not running!!" $Mail-list

fi

相关热词搜索:mysql

上一篇: SQL Server 镜像证书过期处理
下一篇:最后一页