检测apache状态,当apache处于非running状态如何脚本启动

编写脚本内容

#!/bin/bash
URL="http://127.0.0.1/"
curlit()
{
curl --connect-timeout 15 --max-time 20 --head --silent "$URL" | grep '200'
}
doit()
{
if ! curlit; then
systemctl restart httpd > /dev/null
fi
}
while true; do
doit > /dev/null
sleep 10
done

把这个.sh文件权限设为755

chmod 755 xxx.sh

最后使用命令

sh test.sh &

&保证了ssh远程登录操作后需要退出还能保证放到后台执行,不然文件会在退出的时候跟着一起退出执行

原文地址:https://www.cnblogs.com/cnqfz/p/8670006.html