#!/bin/sh
#cat << EOF
#+--------------------------------------------------------------------------+
#| === mysql check=== |
#+--------------------------------------------------------------------------+
#EOF
PORT=`netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ '{print $5}'`
MYSQLIP=`ifconfig eth0|awk '/inet/{print $2}'|cut -c 6-`
while [ `whoami` == "root" ]
do
if [ "$PORT" == "3306" ];then
echo "mysql is running......"
else
echo "restart mysql"
redis-cli flushall
sudo service mysql restart
sleep 30
PORT2=`netstat -na|grep "LISTEN"|grep "3306"|awk -F[:" "]+ '{print $5}'`
if [ "$PORT2" == "3306" ];then
echo "mysql restart successful......"
echo "server: $MYSQLIP ukcnshop mysql is down,but it auto restart mysql!" > /var/log/sumymsg
mail -s "warn!server: $MYSQLIP ukcnshop mysql is restart" 123456789\@qq.com < /var/log/sumymsg
mail -s "warn!server: $MYSQLIP ukcnshop mysql is restart" 123456789\@hotmail.com < /var/log/sumymsg
mail -s "warn!server: $MYSQLIP ukcnshop mysql is restart" 123456789\@qq.com < /var/log/sumymsg
else
echo "mysql restart failure......"
echo "server: $MYSQLIP ukcnshop mysql is down,please try to restart mysql!" > /var/log/mymsg
mail -s "warn!server: $MYSQLIP ukcnshop mysql is down" 123456789\@qq.com < /var/log/mymsg
mail -s "warn!server: $MYSQLIP ukcnshop mysql is down" 123456789\@hotmail.com < /var/log/mymsg
mail -s "warn!server: $MYSQLIP ukcnshop mysql is down" 123456789\@qq.com < /var/log/mymsg
fi
fi
break
done