1 #!/bin/bash 1
2 url=http://www.baidu.com
3 #url=http://fralychen.fralychen
4
5
6 check_http(){
7 status_code=$(curl -I -m 10 -o /dev/null -s -w %{http_code}"\n" $url)
8 #status_code=$(curl -m 5 -w %{http_code} $url | grep 200)
9 echo "http_code:"$status_code
10 }
11
12 while :
13 do
14 check_http
15 date=$(date +%Y%m%d-%H:%M:%S)
16
17 if [ $status_code -ne 200 ];then
18 echo $url---------${status_code}--------$date >> /var/log/check_http.log
19 else
20 echo $url---------${status_code}--------$date >> /var/log/check_http.log
21 fi
22 sleep 5
23 done