How do I save or redirect stdout and stderr into different files?

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?

Adblock detected 😱

My website is made possible by displaying online advertisements to my visitors. I get it! Ads are annoying but they help keep this website running. It is hard to keep the site running and producing new content when so many people block ads. Please consider donating money to the nixCraft via PayPal/Bitcoin, or become a supporter using Patreon.

A. It is not that hard if you know howto redirect stderr, stdout and 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.

Posted by: Vivek Gite

The author is the creator of nixCraft and a seasoned sysadmin, DevOps engineer, and a trainer for the Linux operating system/Unix shell scripting. Get the latest tutorials on SysAdmin, Linux/Unix and open source topics via RSS/XML feed or weekly email newsletter.

Your support makes a big difference:

I have a small favor to ask. More people are reading the nixCraft. Many of you block advertising which is your right, and advertising revenues are not sufficient to cover my operating costs. So you can see why I need to ask for your help. The nixCraft takes a lot of my time and hard work to produce. If everyone who reads nixCraft, who likes it, helps fund it, my future would be more secure. You can donate as little as $1 to support nixCraft: