shell批量检查N个网站地址是否正常(debian/centos)

简介:
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,如需转载请自行联系原作者
目录
相关文章
|
Shell Linux UED
|
安全 Shell Linux
【Shell 命令集合 磁盘维护】Linux 检查和修复Minix文件系统 fsck.minix命令使用教程
【Shell 命令集合 磁盘维护】Linux 检查和修复Minix文件系统 fsck.minix命令使用教程
156 0
|
存储 监控 Shell
【Shell 命令集合 磁盘管理 】Linux 检查磁盘空间限制的状态 repquota命令使用指南
【Shell 命令集合 磁盘管理 】Linux 检查磁盘空间限制的状态 repquota命令使用指南
184 0
|
1月前
|
Ubuntu Linux 索引
Centos 7、Debian及Ubuntu系统中安装和验证tree命令的指南。
通过上述步骤,我们可以在CentOS 7、Debian和Ubuntu系统中安装并验证 `tree`命令。在命令行界面中执行安装命令,然后通过版本检查确认安装成功。这保证了在多个平台上 `tree`命令的一致性和可用性,使得用户无论在哪种Linux发行版上都能使用此工具浏览目录结构。
249 78
|
算法 Shell Linux
【Shell 命令集合 磁盘维护 】Linux 检查和修复文件系统错误 fsck命令使用教程
【Shell 命令集合 磁盘维护 】Linux 检查和修复文件系统错误 fsck命令使用教程
268 0
|
4月前
|
Linux Shell
Centos或Linux编写一键式Shell脚本删除用户、组指导手册
Centos或Linux编写一键式Shell脚本删除用户、组指导手册
124 4
|
4月前
|
Linux Shell 数据安全/隐私保护
Centos或Linux编写一键式Shell脚本创建用户、组、目录分配权限指导手册
Centos或Linux编写一键式Shell脚本创建用户、组、目录分配权限指导手册
269 3
|
存储 安全 Ubuntu
CentOS 与 Debian:主要相似点和不同点
【8月更文挑战第27天】
888 2
CentOS 与 Debian:主要相似点和不同点
|
网络协议 Shell Linux
Shell脚本配置Centos静态ip地址
这是一个用于在CentOS上设置静态IP的Shell脚本摘要: - 脚本交互式获取用户输入的IP地址、子网掩码、网关和DNS。 - 使用`sed`命令动态更新`/etc/sysconfig/network-scripts/ifcfg-ENS33`配置文件。 - 修改`BOOTPROTO`为`static`,并设置IP、NETMASK、GATEWAY和DNS1字段。 - 用`systemctl restart network`重启网络服务。 - 提示用户新配置的静态IP信息。
383 5
|
Ubuntu Linux 测试技术
下载ISO镜像的方法 Debian、Red Hat 、CentOS、Ubuntu、Kali Linux🌐
Debian、Red Hat、CentOS、Ubuntu与Kali Linux均为知名Linux发行版。下载Debian须访问官网并按计算机架构选ISO文件。Red Hat下载通常需订阅账户,可从官网登录后获取。CentOS可从官网或镜像站点下载,注意CentOS 8已停更。Ubuntu下载简便,官网直接选取版本及架构即可。Kali Linux专为安全测试设计,官网提供直接下载ISO镜像服务。
2892 0