shell检测网站状态码和访问时间


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
[root@hddcluster2 script]# cat test_site.sh 
#!/bin/bash  
   
SITES=("http://10.0.0.2" "http://www.163.com"# 要监控的网站  
NOTICE_EMAIL='me@example.com'                                 # 管理员电邮  
DATE=$(date +%Y-%m-%d' '%H:%M:%S)
 
function SENDMAIL()
{
         echo $1         
}
 
 
function CHECK_SITE_CODE()
{
# 循环判断每个site  
        for site in ${SITES[*]}; do  
   
            printf "start to access ${site}\n"  
            site_code=$(curl -o /dev/null -s -w %{http_code} "${site}")  
   
            printf "$(date '+%Y-%m-%d %H:%M:%S')\n"  
            printf "site http code return:${site_code}\n\n"
            if [ ${site_code} != 200 ];
                then
                        echo "Subject: ${site} can't access ${DATE}" | SENDMAIL ${NOTICE_EMAIL}  
            fi
done
}
 
function MAX_ACCESS_TIME()
{
       for site in ${SITES[*]}; do 
        site_access_time=$(curl -o /dev/null -s -w "time_connect: %{time_connect}\ntime_starttransfer: %{time_starttransfer}\ntime_total: %{time_total}" "${site}")
        echo  "$site"
        time_total=${site_access_time##*:}  
        #echo "$time_total"
        printf "site access time\n${time_total}\n"
        var=${time_total%.*}
                if [ ${var} -ge 2 ];
                        then
                                echo "Subject: ${site} can't access ${DATE} " | SENDMAIL ${NOTICE_EMAIL}
                fi
       done
}
 
function SEND_MAIL()
{
        /usr/local/python
}
 
 
echo "check the httpd code"
CHECK_SITE_CODE
echo "-----------------------------------------"\n
echo "check max access time"
MAX_ACCESS_TIME




本文转自 yanconggod 51CTO博客,原文链接:http://blog.51cto.com/yanconggod/1906247
上一篇:对待拷贝构造函数和赋值函数的3种境界


下一篇:C#内存操作