shell監控mysql主從同步

#!/bin/bahmysql

#check_master-slave_statussql

#check_time=10mide

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

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

STATUS=$(mysql -uroot -p123456 -e"show slave status\G;|grep -i running")io

IO_env=`echo $STATUS|grep -i io|awk {'print $2'}`ast

SQL_env=`echo $STATUS|grep -i sql|awk {'print $2'}`class

DATE=`date +"%y-%m-%d %H:%M:%S"`awk


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

  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

相關文章
相關標籤/搜索