我有特定服务的网址列表。 想要根据响应验证所有运行或不运行的URL,并打印特定服务的状态未运行。主要问题是如何显示特定服务未运行。
| ITEM | S_A_AMOUNT | S_B_AMOUNT | S_C_AMOUNT |
|------|------------|------------|------------|
| 1 | 4 | 4 | 3 |
| 2 | 8 | 8 | 6 |
softwareurls.txt:example
while read url; do
curl -o /dev/null --silent --head --write-out '%{http_code}' "$url"
# echo " $LINE"
done < softwareurls.txt
status="$(curl -Is $url | head -1)"
validate=( $stats )
if [ ${validate[-2]} == "200" ]; then
echo OK
else
echo NOT RESPONDING
fi
答案 0 :(得分:0)
我是这样做的:
#!/bin/bash
#
while read service
do
url=$(echo $service | cut -d'=' -f2)
status=$(curl -o /dev/null --silent --head --write-out '%{http_code}' "$url")
if [ $status == '200' -o $status == '301' -o $status = '302' ]
then
echo "$url: OK"
else
echo "$url: NOT RESPONDING"
fi
done < softwareurls.txt
注意:
url=$()
行。$status=$()
行。我希望这有帮助,Nic。
答案 1 :(得分:0)
您可以尝试这个,
#!/bin/bash
function validate_url(){
url=http://nginx.org/download/nginx-1.16.1.tar.gz
if [[ `wget -S --spider $url 2>&1 | grep 'HTTP/1.1 200 OK'` ]]; then
return 0
else
return 1
fi
}
if validate_url $endpoint; then
echo "NGINX-1.16 is a valid URL"
else
echo "NGINX-1.16 is invalid URL"
fi
https://github.com/laksgreen/URL-validator/blob/master/url_scripts.sh