Skip to content

Instantly share code, notes, and snippets.

@davidalger
Created May 26, 2017 17:36
Show Gist options
  • Save davidalger/7441cc05378475d1f7795511d2d724ab to your computer and use it in GitHub Desktop.
Save davidalger/7441cc05378475d1f7795511d2d724ab to your computer and use it in GitHub Desktop.
Check list of URLs for HTTP status codes
#!/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