#!/bin/bash
MYSQLPORT=`netstat -antlp |grep "LISTEN" ` |grep "3306" |awk -F[:""]+ ‘{print $4}‘
MYSQLIP = `ifconfig eth0` |grep "inet addr" |awk -F[:""]+ ‘{print $4}‘
STATUS = $(/usr/local/mysql/bin/mysql -uroot -ppassword -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 == "3306"" ]
then
echo "mysql is runing"
else
mail -s "warn! server: $MYSQLIP mysql is down" [email protected]
fi
if ["$IO_env" ="yes" -a "$SQL_env" = "yes"]
then
echo "Slave is running!"
else
echo "##### $date####" >>/tmp/check_mysql_slave.log
echo"SLAVE is not runing !" >>/data/data/chek_mysql_slave.log
mail -s "warn!" $MYSQLIP_replicate_error" [email protected] <</tmp/check_mysql_slave.log
fi
crontal -l
*/15 * * * * /bin/sh /root/mysql.sh