闲来无事,自己写了一个MySQL进程检查的脚本。想想初学编程时候到处去网上搜的经历,忽然想笑。我是运维工程师,我也想说:“I am a Coder!”。
#!/bin/bash
#DATE 2013/11/25
#MAIL gccmx@163.com
#FUNCTION check the mysql status,if not 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
return 200
else
return 500
fi
}
startMysql(){
/etc/init.d/mysqld start
}
checkMysql
if [ $? == 200 ];then
echo "Mysql is running..."
else
startMysql
checkMysql
if [ $? != 200 ];then
while true
do
killall mysqld
sleep 2
[ $? != 0 ]&&break
done
startMysql
fi
fi
相关阅读:
Linux Shell参数替换 http://www.linuxidc.com/Linux/2013-06/85356.htm
Shell for参数 http://www.linuxidc.com/Linux/2013-07/87335.htm
Linux/Unix Shell 参数传递到SQL脚本 http://www.linuxidc.com/Linux/2013-03/80568.htm
Shell脚本中参数传递方法介绍 http://www.linuxidc.com/Linux/2012-08/69155.htm
Shell脚本传递命令行参数 http://www.linuxidc.com/Linux/2012-01/52192.htm
