Do you want/need STDERR and STDOUT separated or in the same file?
If you're only after the latter, I think the following might do the trick (may be bash-only, may be POSICX-compliant, use with care, no warranties, etc, etc, so on and so forth):
exec 3>&1 # Save current stdout on fd 3
exec > /tmp/log 2>&1 # redirect stdout and stderr to the log file
tail -f /tmp/log >&3 & # Start a tail
"$@" # execute the passed-in command line
RV=$? # save exit status
kill %tail # kill the output
wait # wait for it to finish
exit $RV # and pass back the saved exit status
Simply pass in the script you want to log. If you want stdout and stderr archived separately, it gets a bit trickier. Also, you may want to use a sensible way of picking the log file.
no subject
Date: 2012-07-31 04:12 pm (UTC)If you're only after the latter, I think the following might do the trick (may be bash-only, may be POSICX-compliant, use with care, no warranties, etc, etc, so on and so forth):
Simply pass in the script you want to log. If you want stdout and stderr archived separately, it gets a bit trickier. Also, you may want to use a sensible way of picking the log file.