#!/bin/bash
mysql主从状态监测
原创
©著作权归作者所有:来自51CTO博客作者zhangfang2012的原创作品,请联系作者获取转载授权,否则将追究法律责任
#check MySQL_Slave Status
#crontab time 00:10
MYSQLPORT=`netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ '{print $4}'`
MYSQLIP=`ifconfig eth0|grep "inet addr" | awk -F[:" "]+ '{print $4}'`
STATUS=$(mysql -u root -S /var/lib/mysql/mysql.sock -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}'`
DATA=`date +"%y-%m-%d %H:%M:%S"`
if [ "$MYSQLPORT" == "3306" ]
then
echo "mysql is running"
else
mail -s "warn!server: $MYSQLIP mysql is down" 18801457794@139.com
fi
if [ "$IO_env" == "Yes" -a "$SQL_env" == "Yes" ]
then
echo "Slave is running!"
else
echo "########## $DATA ##########" >>/data/data/check_mysql_slave.log
echo "Slave is not running!" >> /data/data/check_mysql_slave.log
echo "Slave is not running!" | mail -s "warn! $MYSQLIP MySQL Slave is not running" 18801457794@139.com
fi
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章