脚本:
- #!/bin/bash
- count=0
- #尝试循环10次后退出
- while [ $count -lt 10 ]
- do
- pgrep -x mysqld >/dev/null
- if [ $? -ne 0 ];then
- count=$[$count+1]
- #不能使用service mysqld start,启动不成功
- /etc/init.d/mysqld stop
- /etc/init.d/mysqld start
- else
- echo “MySQL server is running .”
- break
- fi
- done
- if [ $count -ne 0 ];then
- #写入日志文件,不需要可以注释掉
- echo -e “At time: ` date "+%Y-%m-%d %H:%M:%S"` :MySQL is stop . Trying to restart $count times .\n” >>/root/sqllog.txt
- fi
复制代码
原文链接:https://blog.csdn.net/qq_40622375/article/details/95739034 |