Skip to content

Instantly share code, notes, and snippets.

@kidsil
Forked from hrwgc/validate.sh
Last active January 23, 2018 16:31
Show Gist options
  • Save kidsil/cc9c91b1520cffeee4c0cb095a5f12ea to your computer and use it in GitHub Desktop.
Save kidsil/cc9c91b1520cffeee4c0cb095a5f12ea 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
}
url="URL_TO_CHECK"
if `validate_url $url >/dev/null`; then echo "FILE IS READY!!!"; else echo "does not exist"; fi
@kidsil
Copy link
Author

kidsil commented Jan 23, 2018

Great way to have it checked every 60 seconds:
watch -n60 bash validate.sh

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment