Last active
January 22, 2019 16:15
-
-
Save jpbalarini/19eed3c83afa9f9e8f274226fb15df4c to your computer and use it in GitHub Desktop.
Batch check URL status code
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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