Created
May 26, 2017 17:36
-
-
Save davidalger/7441cc05378475d1f7795511d2d724ab to your computer and use it in GitHub Desktop.
Check list of URLs for HTTP status codes
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
#!/usr/bin/env bash | |
set -e | |
if [[ ! -f "$1" ]]; then | |
echo "Usage: $(basename $0) <filepath>" | |
echo "" | |
echo " <filepath> path to file with list of URLs to check (one per line)" | |
echo "" | |
exit -1 | |
fi | |
function check_url { | |
url="$1" | |
result="$(curl -Is "$url")" | |
status="$(echo -n "$result" | grep HTTP/1 | cut -d' ' -f2)" | |
location= | |
if [[ $status = "302" ]] || [[ $status = "301" ]]; then | |
location="$(echo -n "$result" | grep Location: | cut -d' ' -f2)" | |
fi | |
echo "$status,$url,$location" | |
sleep 0.25 | |
} | |
echo "http_status,check_url,http_location" | |
for line in $(cat $1); do | |
check_url "$line" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment