Skip to content

Instantly share code, notes, and snippets.

@hoto
Forked from hrwgc/validate.sh
Created August 10, 2017 12:27
Show Gist options
  • Save hoto/2051b62bd04a38893c7c91942ac662f0 to your computer and use it in GitHub Desktop.
Save hoto/2051b62bd04a38893c7c91942ac662f0 to your computer and use it in GitHub Desktop.
bash wget - check if file exists at url before downloading
#!/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