分类: Mysql/postgreSQL
2013-03-21 11:36:04
#!/bin/bash
DATE=`date +%Y%m%d`
TIME=`date +%X`
DATE_TIME=$DATE' '$TIME
DB_USER=""
DB_PASSWD=""
MYSQL_DIR=/usr/local/mysql/bin/mysql
MYSQLPORT=`netstat -na|grep "LISTEN"|grep "3307"|awk -F[:" "]+ '{print $4}'`
MYSQLIP=`ifconfig eth0|grep "inet addr" | awk -F[:" "]+ '{print $4}'`
STATUS=$($MYSQL_DRI -u$DB_USER -p$DB_PASSWD -S /data1/mysql/mysql.sock -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}'`
if [ "$MYSQLPORT" == "3307" ]
then
echo "###################" $DATE_TIME "########################">>/home/Justin/check_mysql_slave_yes.log
echo "mysql is running" >>/home/Justin/check_mysql_slave_yes.log
else
echo "mysql is not running">>/home/Justin/check_mysql_slave_no.log
fi
#echo $IO_env $SQL_env
if [ "$IO_env" = "Yes" -a "$SQL_env" = "Yes" ]
#if [ "$IO_env" = "Yes" ]&&[ "$SQL_env" = "Yes" ]
then
echo "Slave is running!" >>/home/Justin/check_mysql_slave_yes.log
echo "-----------------------------------------------------------">>/home/Justin/check_mysql_slave_yes.log
echo "
">>/home/Justin/check_mysql_slave_yes.log
else
echo "###################" $DATE_TIME "########################">> /home/Justin/check_mysql_slave_no.log
echo "Slave is not running!" >> /home/Justin/check_mysql_slave_no.log
fi
在crontab中设定10分钟或5分钟运行一次脚本