#!/bin/sh
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-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}‘`
function checkMysqlStatus(){
if [ "$MYSQLPORT" =="3306" ]
then
/usr/local/mysql/bin/mysql --connect_timeout=5 -e "showdatabases;" &>/dev/null 2>&1
if [ $? -ne 0 ]
then
echo "Server: $MYSQLIP mysqlis down, please try to restart mysql by manual!" > /var/log/mysqlerr
else
echo "mysql isrunning..."
fi
else
echo "WARN!Server: $MYSQLIP mysqlis down."
fi
}
checkMysqlStatus
if [ "$IO_env" ="Yes" -a "$SQL_env" = "Yes" ]
then
echo "MySQL Slave is running!"
else
echo "####### $DATA #########">>/data/mysql_slave_status.log
echo "MySQL Slave is not running!" >> /data//mysql_slave_status.log
echo "MySQL Slave is not running!"
fi
本文出自 “11300506” 博客,请务必保留此出处http://11310506.blog.51cto.com/11300506/1962340
原文地址:http://11310506.blog.51cto.com/11300506/1962340