redirecting STDOUT & STDERR

In bash, I need to send the STDOUT and STDERR from a command to one file, and then just STDERR to another file. Doing one or the other using redirects is easy, but trying to do both at once is a bit tricky. Anyone have any ideas?

my_command >/my/file 2>&1

bash has a shortcut for this

my_command &>/my/file

Cheers
ZB

That works for combining them, but I need to capture both in one file and capture SDTERR in another file. Can you go further?

my_command >/path/to/stdout.txt 2>/path/to/stderr.txt

man bash for details

That command will separate them in separate files, but again, I need both in one file and just STDERR in another file.

Try "tee" for the stderr.

I've been using tee, but the best I can do is direct STDOUT and STDERR to the screen and STDERR to a file. I need both sets in separate files. Here's the command I've been playing with:

cat input.file1 input.file2 3>&1 >&2 2>&3 3>&- |tee test.log

I grabbed it from post on this forum:

http://www.unix.com/showthread.php?t=7644

Ah now I see

(( my_command 3>&1 1>&2 2>&3 ) | tee error_only.log ) > all.log 2>&1

Cheers
ZB

That did it! Thanks for your help!

Alternatively, use the following method to trap all errors in your script.

debug="off"
if [[ $debug = "on" ]]
  then
    set -x
fi
exec 2>>error.log                  # Send all the errors to error.log