Skip to content

Instantly share code, notes, and snippets.

@bitsgalore
Last active November 16, 2017 17:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bitsgalore/fae328fa5e53b3b63ff6523bf28192ce to your computer and use it in GitHub Desktop.
Save bitsgalore/fae328fa5e53b3b63ff6523bf28192ce to your computer and use it in GitHub Desktop.
#!/bin/bash
# Check HTTP status for list of URLs
#
# Uses curl: https://curl.haxx.se/
# Display usage message if command line does not contain expected
# number of arguments
if [ "$#" -ne 2 ] ; then
echo "Usage: checkHttpStatus.sh fileIn fileOut" >&2
exit 1
fi
# File I/O
fileIn="$1"
fileOut="$2"
# Remove fileOut if it exists already
if [ -f $fileOut ] ; then
rm $fileOut
fi
# Write header line
echo url,status >> $fileOut
# Iterate over all URLs in fileIn
while read url; do
# Check status (https://superuser.com/questions/272265/getting-curl-to-output-http-status-code)
status=$(curl -s -o /dev/null -I -L -w "%{http_code}" $url)
# Add url, status code to output file
echo \"$url\",$status >> $fileOut
done <$fileIn
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment