9

In a bash script, I must download a file from the web. I use the wget command for doing this. I would like to log the output of the wget command, and at "the same time" have the output prompting on terminal.

I searched in the man wget without finding the way to achieve that.

It seems that if you turn on the log with -o or -a parameter, then the prompt output is automatically 'redirected' to the log file, and nothing is shown on the terminal while executing the script, until it has completed the download.

wget -a wget_log --no-check-certificate --auth-no-challenge --http-user=$jen_uname --http-password=$jen_psswd link_to_the_file

Is it possible to do both? Output on prompt and writing on log file?

1
  • Just to be clear - you want the output of wget to go both to a log file and to the terminal?
    – mjturner
    May 8, 2014 at 12:39

1 Answer 1

17

You use the lovely tee command to do this:

wget --no-check-certificate --auth-no-challenge --http-user=$jen_uname --http-password=$jen_psswd 2>&1 | tee -a wget_log

THe 2>&1 means that STDERR goes to the same place as STDOUT, and they're both piped to tee. The -a means append. tee will then send the output both to wget_log and to STDOUT.

2
  • great! thankyou jenny for the clear explaination!
    – lese
    May 8, 2014 at 14:47
  • wget is just outputting to STDOUT -- tee is designed specifically for outputting to a file and STDOUT at the same time. man tee doesn't make this clear. -- ( 2&>1 stderr is redirected to stdout so errors come along for the ride).
    – Able Mac
    Aug 10, 2019 at 15:39

You must log in to answer this question.

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