标签:监控、数据库、脚本
操作系统: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
本文出自 “sky9890” 博客,请务必保留此出处http://sky9896.blog.51cto.com/2330653/1946270
标签:监控、数据库、脚本
原文地址:http://sky9896.blog.51cto.com/2330653/1946270