Hi,
1) Use the
tee command:
command | tee outfile : This will sent stdout to terminal and to outfile
If you want to redirect stderr to outfile too:
command 2>&1 | tee outfile
2) I'm not sure what it is you want:
Quote:
write a error message to stout, and the log and then redirect stderror to the log
|
Maybe the following does what you want:
command 1>/tmp/out 2>&1 || { echo "Oops..." ; cat /tmp/out ; exit 1 ; }
command2
The output (stdout and stderr) is redirected to /tmp/out. If command fails everything after || is executed, if command is
ok then command 2 will be executed.
If the part after || is executed the following happens:
An 'error' is displayed ( echo "Oops..." ),
All the output is shown ( cat /tmp/out ), remember both stderr and stdout are in this file,
The script exits with an appropriate exit code (1 in this case).
Hope this helps.