#!/bin/bash #check MySQL_Slave Status #crontab time 00:10 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 root -p'xxx' -S /usr/local/mysql/mysql.sock -e "show slave statusG" | grep -i "Running:"` IO_env=`echo $STATUS | grep IO | awk '{print $2}'` SQL_env=`echo $STATUS | grep SQL | awk '{print $4}'` Seconds=`/usr/local/mysql/bin/mysql -u root -p'xxx' -S /usr/local/mysql/mysql.sock -e "show slave statusG" | grep -i "Seconds_Behind_Master" | awk '{print $2}'` #SQL_env1=`echo $STATUS | grep SQL` DATA=`date +"%y-%m-%d %H:%M:%S"` #echo "$STATUS" #echo "$SQL_env" #echo "$SQL_env1" if [ "$MYSQLPORT" == "3306" ] then echo "mysql is running" else echo "数据库没有启动" | mail -s 'warn!server: mysqlBI slave is down' xx@163.com,xx@qq.com,baiyufeideyouxiang@163.com fi if [ "$IO_env" == 'Yes' -a "$SQL_env" == 'Yes' ] then echo "Slave is running!" else echo "Slave is not running!" 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!server: mysqlBI slave is down' xx@163.com,xx@163.com fi if [ "$Seconds" -lt "500" ] then echo "Slave is running!" else echo "Slave is not running!" echo "####### $DATA #########">> /data/data/check_mysql_slave.log echo "Slave is not running!" >> /data/data/check_mysql_slave.log echo "mysqlBI slave is down.The Seconds slowly " | mail -s ' mysqlBI slave is down.The Seconds slowly' xx@163.com,xxx@163.com fi