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

Florin Andrei florin at andrei.myip.org
Fri Mar 26 14:11:04 PST 2010


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.

-- 
Florin Andrei
http://florin.myip.org/




More information about the svlug mailing list