Skip to content

Instantly share code, notes, and snippets.

@hrwgc
Created November 13, 2013 19:57
Show Gist options
  • Star 60 You must be signed in to star a gist
  • Fork 15 You must be signed in to fork a gist
  • Save hrwgc/7455343 to your computer and use it in GitHub Desktop.
Save hrwgc/7455343 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
}
@helpinghandindia1
Copy link

hello Team,
Can you tell some solution for random file.
we need to download file daily from https url which is having random name for current data and time .
Starting name is fix and file last part is daily changed due to date and time.
current we use for loop for same but not success output always.
thanks

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