Q. I need to run a program called oraMon.pl. However this program is run from cron job. It report error to stderr and normal output to stdout. How do I save stdout, stderr and both into 3 separate log files?
A. It is not that hard if you know howto redirect stderr, stdout and a small command called tee.
=> fd0 is stdin
=> fd1 is stdout
=> fd2 is stderr
There are two formats for redirecting standard output and standard error:
&>word
and
>&word
For example anything written to fd2 to the same place as output to fd1, you will use:
2>&1
tee command read from standard input and write to standard output and file.
So to send stderr to /tmp/errors.log, stdout to /tmp/output.log and both to /tmp/final.log, type as follows:
((/path/to/oraMon.pl 2>&1 1>&3 | tee /tmp/errors.log) 3>&1 1>&2 | tee /tmp/output.log) > /tmp/final.log 2>&1
Labels
- news (101)
- Linux (72)
- tips (36)
- ubuntu (32)
- hardware (24)
- videos (24)
- howtos (21)
- kde (20)
- open source (20)
- solaris (18)
- solaris interview questions (18)
- external links (10)
- fedora (10)
- windows (10)
- debian (8)
- kernel (8)
- solaris interview questions and answers (8)
- MCSE Videos (6)
- commands (6)
- sun (6)
- linus torvalds (5)
- Sun Solaris 10 CBT (4)
- network administration (4)
- web design (4)
- solaris-express (3)
- backup (2)
- virtualization (1)