-
-
Save googlebe/084a6e4561278ab9757d1cd0cfac7cd0 to your computer and use it in GitHub Desktop.
bash wget - check if file exists at url before downloading
This file contains hidden or 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 'HTTP/1.1 200 OK'` ]]; then echo "true"; fi | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment