ubuntu下使用宝塔计划任务检测apache是否停止,如果停止则启动apache,如果没停止则正常返回。
首先再宝塔计划任务里面新建一个任务:
然后检测代码为:
#!/bin/bash# 检查Apache服务状态 if systemctl status httpd &> /dev/null; thenecho "Apache is running." elseecho "Apache is not running. Attempting to start..."# 尝试启动Apache服务sudo service httpd restart# 检查启动是否成功if systemctl status httpd &> /dev/null; thenecho "Apache has been started successfully."elseecho "Failed to start Apache."fi fi
http://www.syjlp.com/