操作系统:CentOS release 6.8 (Final)

[root@Cacti chapter7]# vi  mysql_method.sh 

echo method1------------

if [ `lsof -i tcp:3306|wc -l` -gt 0 ]     #通过过虑端口号来取值判断 

  then

     echo "MySQL  is Running."

  else

    echo "MySQL is Stopped."

    /etc/init.d/mysqld start

fi


echo method2----------------------

if [ `netstat -lntup|grep mysqld|wc -l ` -gt 0 ]   #通过过滤进程名来取值判断

   then

      echo "MySQL is Running."

   else

      echo "MySQL is Stopped."

   /etc/init.d/mysqld start

fi


echo method3-------------------------

if [ `ps -ef|grep -v grep|grep mysql|wc -l ` -gt 0 ]    #通过传统的方式来判断 

  then

    echo "MySQL is Running."

  else

     echo "MySQL is Stopped."

     /etc/init.d/mysqld start

fi