我写了一些 shell bash 来检查 apache 是否有错误?我使用 curl 我的一页,如果 head 返回 200 ok
,看来 apache 运行良好,否则,做 service httpd restart
,为了监控脚本是否,我写了一些运行日期和状态到一些日志(1.txt)。
apache.sh
#!/bin/bash
curl -I http://www.mydomain.com/check.php 2>/dev/null | head -1 | grep -q " 200 OK"
if [ $? -eq 0 ]; then echo "ok $(date)" >> 1.txt; else service httpd restart;echo "restart $(date)" >> 1.txt; fi
定时任务
*/6 * * * * /bin/sh /home/username/apache.sh >/dev/null 2>&1
但是昨天,我的 apache 还是没了,(子进程 xxxx 仍然没有退出,发送了一个 SIGKILL)。
我在 ssh 命令行 /bin/sh/home/username/apache.sh
中尝试,没有日志写入(1.txt 为空),也没有错误警告。
问题出在哪里?谢谢。
最佳答案
您可以尝试这样一个更简单的脚本:
rc=$(curl -Is -w '%{http_code}' -o /dev/null http://www.mydomain.com/check.php)
if [ $rc -eq 200 ]; then
echo "ok $(date)" >> 1.txt
else
service httpd restart
echo "restart $(date)" >> 1.txt
fi
关于linux - shell bash 代码未运行且没有错误警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19332740/