I would like to direct:

  • Standard out to file.
  • Standard error to the same file.
  • Standard error to console (as well as file).

I've seen this kind of thing:

mycommand 2>&1 | tee test.txt

But it shows standard out on the console where I only want to see errors.

Any help would be appreciated.

link|improve this question

50% accept rate
feedback

1 Answer

up vote 1 down vote accepted

This is not optimal but it should do:

exec 3>mylogfile; mycmd 2>&1 >&3 | tee >(tee >&3);exec 3>&-;

have fun playing with this.

link|improve this answer
Thanks for this. Seems to work ok on most of our scripts. Have got one script which I'm running with this, which just hangs until I Ctrl-C it. It finishes straight away without the "tee >(tee >&3)" bit, but hangs around when that bit is there. Will debug it a bit more. – user22106 Apr 6 '11 at 0:24
feedback

Your Answer

 
or
required, but never shown

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