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