Store and Show Errors with logerrs

logerrs This simple script by Maarten Litmaath runs a command, logs any error messages to a file and also sends them to standard error. Because the standard error usually goes to your screen, this lets you see the errors and log them in a file too.

The script's first argument is the log filename. Then type the command and any other arguments for it. Here's an example of running cat foo bar and logging errors to a file named errors. The foo file exists; the bar file doesn't:

$ cat foo hello world $ logerrs errors cat foo bar hello world bar: No such file or directory $ cat errors bar: No such file or directory

These two lines of the script do the work:

exec 3>&1 "$@" 2>&1 >&3 | tee -a "$ERRLOG" >&2

If the >& stuff is a mystery and you're interested in the Bourne shell's handling of file descriptors, see articles and .

- MAL, JP