Skip to content

Instantly share code, notes, and snippets.

@digitaljhelms
Last active August 27, 2019 04:34
Show Gist options
  • Save digitaljhelms/f47e162b2c80fe27e9eb1acd0d4ac3c4 to your computer and use it in GitHub Desktop.
Save digitaljhelms/f47e162b2c80fe27e9eb1acd0d4ac3c4 to your computer and use it in GitHub Desktop.
CLI to evaluate the HTTP Code for a list of URLs
#!/bin/bash
while IFS= read -r LINE || [ "$LINE" ]; do
# https://curl.haxx.se/docs/manpage.html
IN=$(curl -o /dev/null --silent --head --write-out "%{http_code};%{redirect_url}" "$LINE")
# https://stackoverflow.com/a/5257398
arrIN=(${IN//;/ })
if [ "${arrIN[0]}" = "301" ] || [ "${arrIN[0]}" = "302" ]; then
printf "${arrIN[0]},$LINE,${arrIN[1]}\n"
else
printf "${arrIN[0]},$LINE\n"
fi
done < "$1"
@digitaljhelms
Copy link
Author

Usage: ./httpcode url-list.txt

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment