tags:

views:

69

answers:

3

Howdy,

Can I configure bash on Linux to write a copy of all stdout and stderr to a regular file, without having to specify the redirection for each command?

Thanks, Kent

+4  A: 

You can use script to create a log of your shell session

Hasturkun
+1  A: 

If you are writing a script, I'd recommend write a shell function and redirect its output. You won't have to redirect each command of that function then. I hardly see any meaning in redirections in interactive shell anyway.

Basilevs
I was pleased to find bash 4.1 offers writing command history to syslog.I'm hoping for that level of convenience in logging the output and error messages.
ktenney
+1  A: 

The exec command, if not given a command to execute, will apply its redirections to the current shell. In my testing, however, this does not seem to work that well for pipes. I'd suggest using a subshell, which you can redirect normally.

(
   echo hello
   echo hello err >&2
) 2>&1 | tee logfile.txt

If you only need a transcript, not a continuous tee, exec >& logfile might work.

Also, a traditional trick is to use a remote login tool (ssh or telnet) piped to tee to create a log of an interactive session. screen also supports logging.

Yann Vernier