Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Batch check URL status code
#!/bin/bash
# usage: sh test_status_codes.sh URLs.txt
# example output: https://www.google.com 200
# It saves all output to url_statuses.txt
FILENAME="$1"
if [ -z "$FILENAME" ]; then
echo "Usage: test_status_codes.sh URLs.txt"
exit
fi
curl_status_code() {
URL="$1"
STATUS_CODE=`curl -A "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.98 Safari/537.36" --silent --globoff --max-time 30 --head -L -X GET --write-out '%{http_code}' $URL -o /dev/null`
if [ "$STATUS_CODE" == "000" ]; then
STATUS_CODE='408' #timeout
fi
echo "$URL $STATUS_CODE"
}
export -f curl_status_code
cat $FILENAME | parallel --jobs 100 -k curl_status_code 2>&1 | tee url_statuses.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.