I am using BASH 4. I am trying to find a way to legitimately prepend output to indicate the type of output that it is. I am able to do this with something kind of like this...
ls -l /tmp/abcdefgh 2> >(sed 's/^/stderr: /') 1> >(sed 's/^/stdout: /')
stderr: ls: cannot access /tmp/abcdefgh: No such file or directory
ls -l /tmp/ 2> >(sed 's/^/stderr: /') 1> >(sed 's/^/stdout: /')
stdout: drwxr-xr-x 3 root root 4096 2010-10-15 09:08 fsck
stdout: drwxr-xr-x 2 root root 4096 2010-09-10 06:01 kernel
stdout: drwxr-xr-x 2 root root 4096 2010-09-10 06:01 temp_keys
...
This seems to do the trick when I am logged in via SSH and run it interactively. However, this does not always work right if I try to just run the command as a remote command via ssh with the command in quotes. I can always get the stdout lines, but sometimes not the stderr lines.
This will produce output...
ssh root@server1 "ls -l /tmp/ 2> >(sed 's/^/stderr: /') 1> >(sed 's/^/stdout: /')"
This will not produce even an error message...
ssh root@server1 "ls -l /tmp/abcdefgh 2> >(sed 's/^/stderr: /') 1> >(sed 's/^/stdout: /')"
However, this shows the wget status results as stderr results (which it should)
ssh root@server1 "wget http://server2/package.rpm 2> >(sed 's/^/stderr: /') 1> >(sed 's/^/stdout: /')"