Skip to content

Instantly share code, notes, and snippets.

@obatiuk
Created February 21, 2017 04:50
Show Gist options
  • Save obatiuk/8030eb0f7fc44453c4aab36b96f311c4 to your computer and use it in GitHub Desktop.
Save obatiuk/8030eb0f7fc44453c4aab36b96f311c4 to your computer and use it in GitHub Desktop.
This script prints HTTP code for the supplied url
#!/bin/bash
url=$1
# Make a HEAD request to the supplied URL
code=$(curl $url -s -L -I -o /dev/null -w '%{http_code}')
if [ $code != "200" ]; then
# Some servers might reject HEAD requests. Downloading 1st byte of the data to get a code
code=$(curl --max-filesize 1 $url -s -L -o /dev/null -w '%{http_code}')
fi
echo $code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment