0

i am using wget to download some file in a bash script. i need to use it like this:

wget -t 20 --content-disposition $link

the problem here is, that i cannot specify the output file since it comes from the server. Is there any way to get the filename from the command itself? So where it was written to further use it in the script?

Thanks a lot!

Cheers

2
  • man wget describes how to save output into a specific file or standard output.
    – AlexD
    Commented Mar 11 at 11:44
  • it's -O but a man wget would already told you which is a requirement for this site to do research before you open the question, so I agree with Alex ;) and welcome
    – djdomi
    Commented Mar 12 at 20:27

2 Answers 2

1

Man wget is telling:

-O file --output-document=file The documents will not be written to the appropriate files, but all will be concatenated together and written to file. If - is used as file, documents will be printed to standard output, disabling link conversion. (Use ./- to print to a file literally named -.) Use of -O is not intended to mean simply "use the name file instead of the one in the URL ;" rather, it is analogous to shell redirection: wget -O file http://foo is intended to work like wget -O - http://foo > file; file will be truncated immediately, and all downloaded content will be written there.

For this reason, -N (for timestamp-checking) is not supported in combination with -O: since file is always newly created, it will always have a very new timestamp. A warning will be issued if this combination is used.

Similarly, using -r or -p with -O may not work as you expect: Wget won't just download the first file to file and then download the rest to their normal names: all downloaded content will be placed in file. This was disabled in version 1.11, but has been reinstated (with a warning) in 1.11.2, as there are some cases where this behavior can actually have some use.

Note that a combination with -k is only permitted when downloading a single document, as in that case it will just convert all relative URIs to external ones; -k makes no sense for multiple URIs when they're all being downloaded to a single file

Shortly answered

wgetOutPut=filename_or_fullpath_and_name
wget -t 20 --content-disposition $link -O $wgetOutPut
2
  • hi, thanks for your help, but it does not solve the problem: i need the filename wich comes from the server for the download. and this name is what i need in the script. the solution for now is this for me: file_name=$(wget -nv -t 20 --content-disposition "$link" 2>&1 | cut -d\" -f2) then i have the name and can download the file.. kind of stupid, but it works
    – pcace
    Commented Mar 13 at 9:14
  • Then please add your own answer.
    – djdomi
    Commented Mar 13 at 12:21
0

thanks for your help, but it does not solve the problem: i need the filename wich comes from the server for the download. and this name is what i need in the script.

The solution for now is this for me:

file_name=$(wget -nv -t 20 --content-disposition "$link" 2>&1 | cut -d\" -f2)

Then i have the name and can download the file.. kind of stupid, but it works.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .