[root@rhel6 ~]# curl -I -s -w "%{http_code}\n" -o /dev/null http://127.0.0.1
200
[root@rhel6 ~]# curl -I http://127.0.0.1 2>/dev/null | head -1 | egrep "200|300|301"
HTTP/1.1 200 OK
#!/bin/bash
if [ $# -ne 1 ];then
echo $"Usage $0 url"
exit 1
fi
while true;do
res=`curl -o /dev/null --connect-timeout 2 -s -w "%{http_code}" $1|grep -E -w "200|301|302"|wc -l`
if [ $res -ne 1 ];then
echo "$1 is down."
else
echo "$1 is ok."
fi
sleep 10
done
Options:
-I/--head Show document info only
-s/--silent Silent mode. Don't output anything
-w/--write-out <format> What to output after completion
-o/--output <file> Write output to <file> instead of stdout
-k/--insecure turn off curl's verification of the certificate
--retry <num> Retry request <num> times if transient problems occur
--connect-timeout <seconds> Maximum time allowed for connection
本文介绍了一个使用curl命令持续监控HTTP服务状态的bash脚本。该脚本每隔10秒检查一次指定URL的状态码,并输出服务是否正常。此外,还展示了curl的一些常用选项及其用法。
410

被折叠的 条评论
为什么被折叠?



