标签:running
#!/bin/bash #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=$(/usr/bin/mysql -S /var/lib/mysql/mysql.sock -e "show slave status\\G" | grep -i "running") STATUS=$(/usr/bin/mysql -uroot -pPASSWD -e "show slave status\\G"|grep "Running" |awk ‘{print $2}‘)) 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" user@mail.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" user@mail.com fi #设置cron每十分钟运行一次 #*/10 * * * * root /bin/sh /root/mysql_slave.sh
本文出自 “棒棒不是糖” 博客,谢绝转载!
标签:running
原文地址:http://ctozhanghe.blog.51cto.com/9880217/1637736