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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
我的博客已迁移到xdoujiang.com请去那边和我交流
==========================Debian=====================================
cat
checkurl.sh
#!/bin/bash
#--------------------------------------------------
# Date:2015-05-04
# Author:jimmygong
# Mail:jimmygong@taomee.com
# Function:check website(curl)
# Version:1.0
#--------------------------------------------------
set
-o nounset
echosucc ()
{
succstatus=
"[ Ok ]"
printf
"\033[32m $succstatus $* \033[0m\n"
}
echofail ()
{
failstatus=
"[ Failure ]"
printf
"\033[31m $failstatus $* \033[0m\n"
exit
1
}
urllist=(
http:
//7938217
.blog.51cto.com
/7928217/1639520
http:
//7938217
.blog.51cto.com
/7928217/1639753
http:
//7938217
.blog.51cto.com
/7928217/1641646
http:
//7938217
.blog.51cto.com
/7928217/1641803
http:
//7938217
.blog.51cto.com/
http:
//oldboy
.blog.51cto.com
http:
//etiantian
.org
10.1.1.1
)
function
checkwait ()
{
echo
-n
"start check url."
for
((i=0;i<3;i++))
do
echo
-n
"."
;
sleep
1
done
echo
}
function
checkurl ()
{
checkwait
cat
/etc/issue
|
head
-1
for
((i=0;i<${
#urllist[*]};i++))
do
status=`curl -o
/dev/null
-s -m 10 --connect-timeout 15 -w
"%{http_code}\n"
${urllist[$i]}`
if
[[ $status ==
'200'
]]
wget -T 15 --tries=1 --spider ${urllist[$i]} >
/dev/null
2>&1
[[ $? -
eq
0 ]]
then
echosucc ${urllist[$i]}
else
echofail ${urllist[$i]}
fi
done
}
checkurl
exit
0
============================说明===============================
执行结果
bash
checkurl.sh
start check url....
Debian GNU
/Linux
6.0 \n \l
[ Ok ] http:
//7938217
.blog.51cto.com
/7928217/1639520
[ Ok ] http:
//7938217
.blog.51cto.com
/7928217/1639753
[ Ok ] http:
//7938217
.blog.51cto.com
/7928217/1641646
[ Ok ] http:
//7938217
.blog.51cto.com
/7928217/1641803
[ Ok ] http:
//7938217
.blog.51cto.com/
[ Ok ] http:
//oldboy
.blog.51cto.com
[ Ok ] http:
//etiantian
.org
[ Failure ] 10.1.1.1
-m
/--max-time
<seconds> 设置最大传输时间
-s
/--silent
静音模式。不输出任何东西
-o
/--output
把输出写到该文件中
-w
/--write-out
[
format
]什么输出完成后
--connect-timeout <seconds> 设置最大请求时间
===========================Centos=====================================
cat
checkurl.sh
#!/bin/bash
#--------------------------------------------------
# Date:2015-05-04
# Author:jimmygong
# Mail:jimmygong@taomee.com
# Function:check website(curl)
# Version:1.0
#--------------------------------------------------
set
-o nounset
source
/etc/init
.d
/functions
urllist=(
http:
//7938217
.blog.51cto.com
/7928217/1639520
http:
//7938217
.blog.51cto.com
/7928217/1639753
http:
//7938217
.blog.51cto.com
/7928217/1641646
http:
//7938217
.blog.51cto.com
/7928217/1641803
http:
//7938217
.blog.51cto.com/
http:
//oldboy
.blog.51cto.com
http:
//etiantian
.org
10.1.1.1
)
function
checkwait ()
{
echo
-n
"start check url."
for
((i=0;i<3;i++))
do
echo
-n
"."
;
sleep
1
done
echo
}
function
checkurl ()
{
checkwait
cat
/etc/issue
|
head
-1
for
((i=0;i<${
#urllist[*]};i++))
do
status=`curl -o
/dev/null
-s -m 10 --connect-timeout 15 -w
"%{http_code}\n"
${urllist[$i]}`
if
[[ $status ==
'200'
]]
wget -T 15 --tries=1 --spider ${urllist[$i]} >
/dev/null
2>&1
[[ $? -
eq
0 ]]
then
action ${urllist[$i]}
/bin/true
else
action ${urllist[$i]}
/bin/false
fi
done
}
checkurl
exit
0
=================================说明==============================
执行结果
bash
checkurl.sh
start check url....
CentOS release 6.6 (Final)
http:
//7938217
.blog.51cto.com
/7928217/1639520
[ OK ]
http:
//7938217
.blog.51cto.com
/7928217/1639753
[ OK ]
http:
//7938217
.blog.51cto.com
/7928217/1641646
[ OK ]
http:
//7938217
.blog.51cto.com
/7928217/1641803
[ OK ]
http:
//7938217
.blog.51cto.com/ [ OK ]
http:
//oldboy
.blog.51cto.com [ OK ]
http:
//etiantian
.org [ OK ]
10.1.1.1 [FAILED]
|
本文转自 xdoujiang 51CTO博客,原文链接:http://blog.51cto.com/7938217/1641899,如需转载请自行联系原作者