Created
February 21, 2017 04:50
-
-
Save obatiuk/8030eb0f7fc44453c4aab36b96f311c4 to your computer and use it in GitHub Desktop.
This script prints HTTP code for the supplied url
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 | |
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