Operating System - HP-UX
1825720 Members
3177 Online
109686 Solutions
New Discussion

Re: Re-direct statements in cron files

 
SOLVED
Go to solution
Debbie Fleith
Regular Advisor

Re-direct statements in cron files

Can someone tell me the difference between these 2 cron jobs (the re-direct portions)?

* * * * * /anyscript 1>/dev/null 2>&1

* * * * * /anyscript &2>> /dev/null

Also, if I want errors from anyscript to go to a file, what is the best redirect statement?
5 REPLIES 5
Rodney Hills
Honored Contributor

Re: Re-direct statements in cron files

1>/dev/null 2>&1
- This will map STDOUT to null and then STDERR to the same as STDOUT (null)

&2>>/dev/null
- I think the "&" will launch the command as a background job, and 2>>/dev/null will step STDERR to null.

HTH

-- Rod Hills
There be dragons...
David DeWitt_2
Frequent Advisor

Re: Re-direct statements in cron files

Debbie,

It looks to me like the first one sends standard out to the bit bucket and then sends standard error as well.

I'm not sure about the second one. It looks sort of like it's trying to run the process in the back ground and send std err to /dev/null?

Maybe one of the hats knows about that one.

-dave
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Re-direct statements in cron files

The 1st example redirect stdout (fdes 1) onto /dev/null and then redirects stderr (fdes 2) to stdout -- which is already redirected to /dev/null. The net effect is that both stdout and stderr are redirected to /dev/null.

If the 2nd example were correctly done then only stderr would be redirected. Stdout would remain unaffected.

The "best" way to redirect errors depends upon what you are trying to do at the moment.
One method from a script is to include a line like this early in the script:

exec 2>>/xxx/myerrs

Now all subsequent stderr output will be appended to the file /xxx/myerrs.

You could also do something like

exec 1>>/xxx/mylog
exec 2>&1

and now stdout and stderr would be sent to a file.
If it ain't broke, I can fix that.
Sanjay_6
Honored Contributor

Re: Re-direct statements in cron files

Hi Debbie,

Maybe this would help you understand how the redirection works.

http://www.unet.univie.ac.at/aix/aixuser/usrosdev/input_output_redir_korn.htm

Hope this helps.

Regds
Michael_356
Frequent Advisor

Re: Re-direct statements in cron files

Hi there,

what is anyscript (the one from '* * * * * /anyscript &2>> /dev/null') for?
Do this script need parameters (something like '&2')?

If it needs this parameter, the rest is just a cute appending to /dev/null.

regards

Michael