通过Shell来监测MySQL状态

#!/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
分享到:
关键词:Linux运维Shell

<< 上一篇

IF语句小练习

下一篇 >>

nginx的Shell启动脚本

网友留言(0 条)

发表评论