shell mysql服务状态检查脚本示例
时间:2014-04-29 02:24 来源:linux.it.net.cn 作者:IT网
#!/bin/bash
#DATE 2013/11/25
#MAIL gccmx@163.com
#FUNCTION check the mysql status,ifnot run start mysql.
#Create by Chenchao Gao
checkMysql(){
CMDCHECK=`lsof -i:3306&>/dev/null`
Port="$?"
PIDCHECK=`ps aux|grep mysqld|grep -v grep`
PID="$?"
if[ "$Port"-eq "0"-a "$PID"-eq 0];then
return200
else
return500
fi
}
startMysql(){
/etc/init.d/mysqld start
}
checkMysql
if[ $? == 200];then
echo "Mysql is running..."
else
startMysql
checkMysql
if[ $? != 200];then
whiletrue
do
killall mysqld
sleep 2
[ $? != 0]&&break
done
startMysql
fi
fi
(责任编辑:IT)
#!/bin/bash #DATE 2013/11/25 #MAIL gccmx@163.com #FUNCTION check the mysql status,ifnot run start mysql. #Create by Chenchao Gao checkMysql(){ CMDCHECK=`lsof -i:3306&>/dev/null` Port="$?" PIDCHECK=`ps aux|grep mysqld|grep -v grep` PID="$?" if[ "$Port"-eq "0"-a "$PID"-eq 0];then return200 else return500 fi } startMysql(){ /etc/init.d/mysqld start } checkMysql if[ $? == 200];then echo "Mysql is running..." else startMysql checkMysql if[ $? != 200];then whiletrue do killall mysqld sleep 2 [ $? != 0]&&break done startMysql fi fi(责任编辑:IT) |