Processes have two common output streams, standard-output (stdout) and standard-error (stderr). Error messages are normally written to stderr.
The ">" redirect only captures stdout. In your example the stdout is already being redirected in the "|" pipelines you've set up.
For any process, stdout is its file descriptor number 1 (this relates to its internal file handle number), stderr is file descriptor number 2. The ">" redirect can have a number on the front of it, ">" is really short for "1>". To grab the standard error use "2>", for example:
Code:
ls doesntexist 2> logfile
to do a whole bunch of commands you can perform them in a sub-shell and capture
its std error - a sub-shell can be started by using brackets:
Code:
(
find /baddir -name x
ls doesntexist
) 2> logfile
Or use curly brackets, {}, if you don't want the overhead of running a sub-shell.
Note that the ordering of redirects can be important - these aren't the same:
Code:
ls goodfile badfile 2>&1 1> result
ls goodfile badfile 1> result 2>&1
Experiment and/or read to find out the difference.
See
Advanced Bash-Scripting Guide
And google for bash scripting FAQ and Howto.