[svlug] logging all output of a bash script, from within the script?

Robert Hajime Lanning lanning at lanning.cc
Fri Mar 26 14:25:48 PST 2010


On 03/26/10 15:11, Florin Andrei wrote:
> How would you satisfy all these conditions with a bash script?
> 
> 1. Log all the output (stdin and stderr) to a file
> 2. Also have the output display normally on the console while it's running
> 3. Do it with a single script (no wrappers)
> 
> This will satisfy #1 and #3 but not #2:
> 
> #!/bin/bash
> exec > file 2>&1
> command1
> command2
> ...
> 
> A wrapper script with tee will satisfy #1 and #2 but not #3:
> 
> #!/bin/bash
> real-script | tee file
> 
> I have no idea how to satisfy all 3 at once.
> 

#! /bin/bash
(
echo this
echo that
...
) 2>&1 | tee file

-- 
END OF LINE
      --MCP




More information about the svlug mailing list