时间:2021-07-01 10:21:17 帮助过:26人阅读
学习shell编程,做了一个检测MYSQL时候启动的脚本,刚学SHELL没几天,欢迎大家给意见和建议
# !bin/bash
MYSQLPID='/var/run/mysqld/mysqld.pid';
if [ ! -f $MYSQLPID ] ; then
service mysqld start &>> mysql.error.log;
if [ $? -ne 0 ] ; then
for i in $(ps -ef|grep mysqld | grep -v grep | awk '{print $2}')
do
kill -9 $i;
done
service mysqld start &>> mysql.error.log;
fi
exit;
fi
PID=$(tail $MYSQLPID);
if [[ X$PID -eq X ]] ; then
rm -rf $MYSQLPID;
if [ $? -eq 0 ] ; then
for i in $(ps -ef|grep mysqld | grep -v grep| awk '{print $2}')
do
kill -9 $i;
done
service mysqld stop &>> mysql.error.log;
service mysqld start &>> mysql.error.log;
else
echo "MYSQL PID 文件删除失败. " 1>> mysql.error.log
fi
fi以上就是一个简单的MYSQL检测实例代码的详细内容,更多请关注Gxl网其它相关文章!