Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

This command does not store the output of my script in the log file:

. myscript.sh | tee -a log_file.log

However this next command does store the output in the log file.

. myscript.sh 2>&1 | tee -a dash_log.log

Why does the second one work and not the first? AFAIK the only difference is that I have told bash to redirect stderr to stdout, and it should not make any difference to what happens with stdout. Yet that first command would not even store the 'error-less' version of stdout in the log file.

And in case it matters: I'm on Ubuntu 12.04 hosted on AWS

EDIT: This was caused by erroneous assumptions of how wget outputs messages. See http://stackoverflow.com/questions/13066518/why-does-wget-output-to-stderr-rather-than-stdout and http://www.gnu.org/software/wget/manual/html_node/Logging-and-Input-File-Options.html

share|improve this question

migrated from serverfault.com Sep 11 '13 at 8:25

This question came from our site for system and network administrators.

can i see the script ? – Danila Ladner Sep 9 '13 at 2:53
I'd rather not include the script actually. The script starts with source ~/.bashrc, then loops through some urls calling wget "theurl.com" --output-document="local/dir/theurl.com" for each one. All the script output comes from wget. – Trindaz Sep 9 '13 at 3:45
and there are no errors from wget, with each entry in the log being of the form something liketimestamp - url; transfer messages; "Saving to: ..."; 0K .......... 31.9M=0s – Trindaz Sep 9 '13 at 3:47
do you have anywhere this: 1>&2? Either in the script itself or in .bashrc which you are sourcing. – Danila Ladner Sep 9 '13 at 4:12
@DanilaLadner no that doesn't appear in the script – Trindaz Sep 9 '13 at 6:27
up vote 3 down vote accepted

It seems likely that your script is writing most or all of it's output to stderr. This is easy to test

myscript.sh > std.out
myscript.sh 2> err.out

then look at the contents of each file and be educated.

I doubt it - the only output from the script comes from calls to wget

Instead of doubting, again this is easy to test

$ wget http://serverfault.com >std.out
--2013-09-09 07:06:25--  http://serverfault.com/
Resolving serverfault.com...
Connecting to serverfault.com||:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 51867 (51K) [text/html]
Saving to: “index.html.6”

100%[=================================================>] 51,867   231K/s  in 0.2s

2013-09-09 07:06:26 (231 KB/s) - “index.html.6” saved [51867/51867]

See, output still gets written to the terminal then try

 $ wget http://serverfault.com 2>err.out


The wget command writes it's output to stderr not stdout.

share|improve this answer
I stand corrected. While it's not clear at all to me why wget would publish "standard" output messages that are not about errors to stderr, that is indeed what it is doing. Not a safe assumption to make at all. – Trindaz Sep 9 '13 at 6:32
I've always figured it writes to STDERR so that if you wget -o - the messages from wget wont get mixed with the payload. – Petter H Sep 9 '13 at 6:51
@PetterH good point - I did discover that on reading the man page, but it still doesn't feel right. I've continued discussion at ubuntuforums.org/showthread.php?t=2173318 – Trindaz Sep 9 '13 at 6:58

Would probably need to see the code but it is probably due to your code writing out to stderr.

share|improve this answer
I doubt it - the only output from the script comes from calls to wget, which completes normally multiple times during the script. – Trindaz Sep 9 '13 at 3:35

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.