Skip to content

Instantly share code, notes, and snippets.

@digitaljhelms

digitaljhelms/httpcode

Last active Aug 27, 2019
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@digitaljhelms digitaljhelms commented Jun 6, 2019

Usage: ./httpcode url-list.txt

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