Bash – wget a file, logging the output and showing the output on prompt

bashlogsoutputshell-scriptwget

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?

Best Answer

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.

Related Question