Created
November 3, 2017 20:40
-
-
Save fn-alves/d917133207f6a77398b47d87531cc38c to your computer and use it in GitHub Desktop.
bash wget - function check is valid file at url before downloading
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
#!/usr/bin/env bash | |
# simple function to check http response code before downloading a remote file | |
# usage: | |
# if `isValidUrl $url >/dev/null`; then dosomething ; else echo "url does not exist!" ; fi | |
function isValidUrl() { | |
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