我的博客已迁移到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]
shell批量检查N个网站地址是否正常(debian/centos)
原创文章标签 shell curl wget 文章分类 开源
©著作权归作者所有:来自51CTO博客作者xdoujiang的原创作品,请联系作者获取转载授权,否则将追究法律责任
下一篇:dnsmasq(内网DNS)
![](https://ucenter.51cto.com/images/noavatar_middle.gif)
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
shell脚本检查网站是否正常
检查Web网站可
linux bash ide 测试命令