Skip to content

Instantly share code, notes, and snippets.

@angelbladex
Forked from hrwgc/validate.sh
Last active August 29, 2015 14:05
Show Gist options
  • Save angelbladex/dad9308bbdb7e18f384a to your computer and use it in GitHub Desktop.
Save angelbladex/dad9308bbdb7e18f384a to your computer and use it in GitHub Desktop.
validate a url with wget
#!/bin/bash
# simple function to check http response code before downloading a remote file
# example usage:
# if `validate_url $url >/dev/null`; then dosomething; else echo "does not exist"; fi
function validate_url(){
if [[ `wget -S --spider $1 2>&1 | grep 'HTTP/1.1 200 OK'` ]]; then
echo "URL exist"
else
echo "Error detected. Check URL or internet connection"
fi
exit
}
if [[ ! -n "$1" ]]; then
echo "URL missing"
exit
fi
validate_url "$1"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment