commit 0a4043af393ad9033de594defbbded26903ebc90 Author: Alexandre Dulaunoy Date: Sun Mar 10 18:45:59 2024 +0100 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) diff --git a/url-check.sh b/url-check.sh new file mode 100644 index 0000000..15428c7 --- /dev/null +++ b/url-check.sh @@ -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 +