Advanced shell scripting question :-)

Michael O'Donnell mod+gnhlug at std.com
Wed Sep 4 23:32:27 EDT 2002


>I want the following three things to happen when I run p:
>
>1. I want both stdout and stderr to go to the screen
>
>2. I want stdout and stderr combined in a file
>
>3. I want an error log file to only contain stderr.
>
>p 2>&1 | tee outnerr # Solves 1 and 2
>
>p 2> errlog     # Solves 3 but breaks 1 and 2
>
>p 2> errlog | tee out # Solves 3 but also breaks 1 and 2.
>
>Any takers?


This might not exactly fit the bill, but it gets you pretty
close, and makes use of some trickery discussed here not
too long ago:

  (p > >(tee stdoutLog) ) 2> >(tee stderrLog)

It satifies #1 by spewing straight to the current tty.  #3
is satisfied because it creates the stderrLog, and you could
satisfy #2 by concatenating the stdoutLog and the stderrLog.




More information about the gnhlug-discuss mailing list