Skip to content

Instantly share code, notes, and snippets.

@angelbladex
Forked from hrwgc/validate.sh
Last active September 3, 2024 15:27
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 -E '200|320|302|303'` ]]; 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