-
-
Save angelbladex/dad9308bbdb7e18f384a to your computer and use it in GitHub Desktop.
validate a url with wget
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 | |
# 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