Skip to content

Instantly share code, notes, and snippets.

@raydog
Created October 14, 2014 20:30
Show Gist options
  • Save raydog/c6977052e1b799143b7b to your computer and use it in GitHub Desktop.
Save raydog/c6977052e1b799143b7b to your computer and use it in GitHub Desktop.
Will take in a file, with URLs on different lines, and will perform a HEAD request for each one, printing HTTP status code along with content length. Outputs results in Markdown
#!/bin/bash
# Will take in a file, with URLs on different lines, and will perform a HEAD request for
# each one, printing HTTP status code along with content length.
if [ $# -ne 1 ] ; then
echo "Usage: bash $0 <file_with_urls>"
exit 1
fi
safestr() {
sed 's/[[:cntrl:]]//g'
}
file_name="$1"
echo "# HTTP Status for URLs in $file_name"
line_no=0
while read line ; do
line_no=$(($line_no + 1))
friendly_name="$(echo -n $line | sed 's/^.*\/\(.*\)/\1/')"
echo "$line_no. File: **$friendly_name**"
headers="$(curl -s --head "$line")"
http_status="$(echo "$headers" | grep ^HTTP | safestr)"
content_len="$(echo "$headers" | grep ^Content-Length | sed 's/.*: \([0-9]*\).*/\1/')"
echo
echo " Status: \`$http_status\`"
echo
echo " Length: \`$content_len\`"
echo
done < "$file_name"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment