new: [url-check] Read a list of URLs from stdin and print if the url is Ok (200 or 301 with one redirect to a 200)

This commit is contained in:
Alexandre Dulaunoy 2024-03-10 18:45:59 +01:00
commit 0a4043af39
Signed by: adulau
GPG key ID: 09E2CD4944E6CBCD

16
url-check.sh Normal file
View file

@ -0,0 +1,16 @@
#!/bin/bash
#
# Read a list of URLs from stdin and print if the url is Ok (200 or 301 with one redirect to a 200)
#
#
while read line
do
status_code=$(curl --write-out %{http_code} --max-redirs 1 --silent --output /dev/null -H "User-Agent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:122.0) Gecko/20100101 Firefox/122.0" -m 2 -s --head --request GET -L ${line})
if [[ "$status_code" -ne 200 ]] ; then
echo "Nok (${status_code}): ${line}"
else
echo "Ok (${status_code}): ${line}"
fi
done