ubuntu下使用宝塔计划任务检测apache是否停止

ubuntu下使用宝塔计划任务检测apache是否停止,如果停止则启动apache,如果没停止则正常返回。

首先再宝塔计划任务里面新建一个任务:

 然后检测代码为:

#!/bin/bash
 
# 检查Apache服务状态
if systemctl status httpd &> /dev/null; then
    echo "Apache is running."
else
    echo "Apache is not running. Attempting to start..."
    # 尝试启动Apache服务
    sudo service httpd restart
    # 检查启动是否成功
    if systemctl status httpd &> /dev/null; then
        echo "Apache has been started successfully."
    else
        echo "Failed to start Apache."
    fi
fi

  http://www.syjlp.com/

posted @ 2025-01-09 03:29  圆柱模板  阅读(34)  评论(0)    收藏  举报