验证网址是否可用

判断网址是否正常##

#!/bin/bash
array=(
	www.baidu.com
	www.sohu.com
	www.google.com
	www.helloworldxhn.com
)

for url in ${array[*]}
do
	res_code=$(curl -I -m 2 $url 2>/dev/null | egrep 200 | wc -l)
	if [ $res_code -eq 1 ]; then
		echo "$url is successful "
	else
		echo "$url is failure"
	fi
done

curl -I 只显示头部
-m 设置最大读取时间

原文地址:https://www.cnblogs.com/xhnxhnu/p/9772730.html