学习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
The above is the detailed content of A simple MYSQL detection example code. For more information, please follow other related articles on the PHP Chinese website!