我的博客已迁移到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]
转载于:https://blog.51cto.com/7938217/1641899