Forum Moderators: bakedjake
example1: crontab task details here ... >/dev/null 2>&1
example2: crontab task details here ... 2>&1 > /dev/null
STDERRand the 1 is
STDOUT, but beyond that I am uncertain of the intended result.
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
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
It took a few reads to let it sink inMaybe because English isn't my native language... ;)
example1: crontab task details here ... >/dev/nullThis will redirect STDOUT to /dev/null but leave STDERR untouched.
example2: crontab task details here ... 2>&1 > /dev/nullThis 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...