#!/bin/sh port=`netstat -antup|grep mysqld|wc -l` process=`ps -ef|grep mysqld|grep -v grep|wc -l` if [ $port -ne 1 ] && [ $process -ne 2 ] then mysql -uroot -p123456 -e "select version();" &>/dev/null if [ $? -ne 0 ] then echo "MySQL is stop at $(date +%F" "%T)" >/tmp/mysqlstop.log # echo "MySQL is stop at $(date +%F" "%T)"|mail -s "MySQL Warning" shnne@shnne.com /etc/init.d/mysqld start fi else echo "MySQL is running." fi