I am working on a bash
script and curl
to download file from a server. I am trying to add date
in format $(date +"%y-%m-%d")
to the file that will be downloaded. Below is my curl call
curl --fail -S -O -C - --location "${HEADERS[@]}" -X GET "$url"
With above call the file is downloading fine (example filename: test.txt). Now I want to add date to the file. I think if we use -o
option then we can add it like curl -o test-$(date +"%y-%m-%d").txt
but in my case I want to store the filename as it is from remote file name. Is it possible to do the same with -O
option?
Also if we add the date to remote file name will it affect the -C -
option? Can we still have the resuming interrupted downloads feature?
Expected output:
Filename after downloading: test-YYYY-MM-DD.txt
P.S: Please let em know if any info is missing. I am working on Ubuntu
and the script will be part of BusyBox
system. Also, sorry if the question is more of a discussion.
2
Answers
What I would do:
You could use:
Whether or not the transfer can be resumed depends on if the server supports byte ranges (you can check by omitting
-s
).