首页 > 代码库 > shell监控mysql主从同步
shell监控mysql主从同步
#!/bin/bah
#check_master-slave_status
#check_time=10m
MYSQLIP=`ifconfig eth1|grep "inet addr"|awk -F[:" "]+{‘print $4‘}`
MYSQLPORT=`netstat -lntp|grep 3306|awk -F[:" "]+ {‘print $5‘}`
STATUS=$(mysql -uroot -p123456 -e"show slave status\G;|grep -i running")
IO_env=`echo $STATUS|grep -i io|awk {‘print $2‘}`
SQL_env=`echo $STATUS|grep -i sql|awk {‘print $2‘}`
DATE=`date +"%y-%m-%d %H:%M:%S"`
if["$MYSQLPORT"=="3306"];then
echo "mysql is running..."
else
mail -s "warn!server:$MYSQLIP mysql is down..." 1243983186@163.com
fi
if["$IO_env"=="yes" -a "$SQL_env"=="yes"];then
echo "slave is running..."
else
echo "###########$DATE##############">> /opt/check_mysql_slave.log
echo "slave is not running...">> /opt/check_mysql_sqlve.log
eceo "slave is not running..."|mail -s "warn!server:$MYSQLIP mysql_slave is not running..." 1243983186@163.com
fi
shell监控mysql主从同步