what is the purpose
Hi,
Please explain what is the purpose of this " > /dev/null 2>&1" in CRON Job, Please Please Explain why the standard out put is sent to Null device and then what is the purpose of this argument 2>&1, Please HELP TIA:confused: |
it just suppresses all output - Stdout is sent to null where it gets blackholed, and then stderr is sent to whereever stdout is going (which we already know is null), otherwise you tend to end up being emailed the output of the scripts, based on the MAILTO setting in the crontab file, which is usually not desirable.
|
Every program in Linux (or any Unix variant) has three standard files available to it:
Normally, the shell intermingles STDOUT and STDERR output, displaying both of the two streams inter-mingled. But, as I said, you can redirect either one or both. So what if you want to just discard something? Well, that's why you've got a nice "bit-bucket," called /dev/null. Anything you write to it drops into the bucket. Anything you read from it is immediate end-of-file. Caution: The bit-bucket must be emptied on a regular basis. (The most common cause of an unexpected system crash is: "bit-bucket overflow.") Bits are very smelly and sticky. (Especially the bits from Windows machines!) Be careful not to spill the bucket's contents on the floor when you empty it: they'll leave an indelible stain on any carpet. ;) |
Is this correct?
> /dev/null 2>&1 will stop all output by sending it to /dev/null > /dev/null stops STDOUT but allows STDERR to be sent > redirects STDOUT 2> redirects STDERR or 2>&1 redirects STDERR and what is the &1 in 2>&1 mean? thanks |
2>&1 sends STDERR to STDOUT, combining the two streams into one.
|
Thanks all , that's a good explanation , was helpful to me
|
Thanks Chris
|
To expand on sundialsvcs, each channel has an associated number:
stdin = 0 stdout = 1 stderr = 2 and you do redirects with the nums, not the names. |
All times are GMT -5. The time now is 02:03 PM. |