1

I would like to direct:

  • Standard output 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 output on the console where I only want to see errors.

1

This is not optimal, but it should do:

exec 3>mylogfile; mycmd 2>&1 >&3 | tee >(tee >&3);exec 3>&-;
|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. – Ben Apr 6 '11 at 0:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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