Last active
August 27, 2019 04:34
-
-
Save digitaljhelms/f47e162b2c80fe27e9eb1acd0d4ac3c4 to your computer and use it in GitHub Desktop.
CLI to evaluate the HTTP Code for a list of URLs
This file contains 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 | |
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" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Usage:
./httpcode url-list.txt