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
    千行代码,Bug何处藏。   纵使上线又怎样,朝令改,夕断肠。
 
                    
                
 
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号