判断网站URL是否正常访问脚本

#!/bin/bash

[ -f /etc/init.d/functions ] && . /etc/init.d/functions

function usage(){
	echo "USAGE:$0 url"
	exit 1
}

RETVAL=0
function CheckUrl(){
	wget -T 10 --spider -t 2 $1 &>/dev/null
	RETVAL=$?
	if [ $RETVAL -eq 0 ];then
		action "$1 url" /bin/true
	else
		action "$1 url" /bin/false
	fi
	return $RETVAL
}

function main(){
	if [ $# -ne 1 ];then
		usage
	fi
	CheckUrl $1
}

main $*

posted @ 2017-05-05 09:08  午夜爬虫  阅读(1580)  评论(0编辑  收藏  举报