homepage Welcome to WebmasterWorld Guest from 54.204.73.126
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
Forum Library, Charter, Moderators: bakedjake

Linux, Unix, and *nix like Operating Systems Forum

    
crontab dev null output
Can you explain the differences?
coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3682871 posted 2:14 am on Jun 25, 2008 (gmt 0)

I've been looking through two different options for sending a crontab task's output to neverland but am uncertain as to the details for the following ... anybody that can explain them?
example1: crontab task details here ... >/dev/null 2>&1 
example2: crontab task details here ... 2>&1 > /dev/null

I know that the 2 is
STDERR and the 1 is STDOUT, but beyond that I am uncertain of the intended result.

 

OutdoorWebcams

5+ Year Member



 
Msg#: 3682871 posted 6:36 am on Jun 25, 2008 (gmt 0)

In example 1 all output is redirected to /dev/null, because you first redirect /dev/stdout to /dev/null and then redirect /dev/stderr to the device where /dev/stdout is pointing to right now and that's /dev/null (redirections take place from left to right).

In example 2 you redirect /dev/stderr to where /dev/stdout is pointing to at that moment and that's probably your screen. It's important here that both file descriptors are still independent, although they point to the same device.
Now you redirect /dev/stdout to /dev/null but /dev/stderr is still pointing to the device where /dev/stdout was pointing to before, and that's still probably your screen.

So example 1 is what you are looking for, because in example 2 error messages are not redirected to /dev/null.

HTH

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3682871 posted 2:48 pm on Jun 25, 2008 (gmt 0)

I use the first example myself but came across the second recently and was trying to wrap my head around the why of it all because it looked like the same thing to me.

Now I get it. It took a few reads to let it sink in but it makes sense. The independent file descriptors and left to right assignment is what I misunderstood. I viewed the redirection as a progressive assignment, passing each on to the next in progressive order as opposed to independent assignment from left to right order.

Makes sense. Thanks!

One follow-up question, or confirmation perhaps; would the following entries produce the same expected redirection?

example1: crontab task details here ... >/dev/null 
example2: crontab task details here ... 2>&1 > /dev/null

OutdoorWebcams

5+ Year Member



 
Msg#: 3682871 posted 4:00 pm on Jun 25, 2008 (gmt 0)

It took a few reads to let it sink in
Maybe because English isn't my native language... ;)

example1: crontab task details here ... >/dev/null
This will redirect STDOUT to /dev/null but leave STDERR untouched.

example2: crontab task details here ... 2>&1 > /dev/null
This is the same as your first example2, it will redirect STDERR to the device/file where STDOUT is pointing to at the beginning of the cronjob (redirection of STDERR to STDOUT is processed first) and then it will redirect STDOUT to /dev/null (leaving STDERR untouched, or better: STDERR still points to the device/file where STDOUT was pointing to at the beginning of the cronjob).

So under normal circumstances both examples would produce the same redirections: STDOUT writes to /dev/null and STDERR onto the screen (not regarding situations where any of these handles were pointing to e.g. a file).

I hope this wasn't more confusing than my first post...

coopster

WebmasterWorld Administrator coopster us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3682871 posted 8:41 pm on Jun 25, 2008 (gmt 0)

Nope, and your English is quite fine. Thanks for the confirmation.
Off to play around a bit now ...

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Hardware and OS Related Technologies / Linux, Unix, and *nix like Operating Systems
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved