LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   what is the purpose (https://www.linuxquestions.org/questions/linux-newbie-8/what-is-the-purpose-785612/)

pradeepjeevan 01-29-2010 09:29 AM

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:

acid_kewpie 01-29-2010 09:34 AM

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.

sundialsvcs 01-29-2010 11:15 AM

Every program in Linux (or any Unix variant) has three standard files available to it:
  • STDIN - the standard input stream
  • STDOUT - the standard output stream (which can be redirected in the shell using ">")
  • STDERR - the standard "error output" stream (which can be redirected using "2>")

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. ;)

etech3 02-10-2010 09:56 AM

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

acid_kewpie 02-10-2010 11:47 AM

2>&1 sends STDERR to STDOUT, combining the two streams into one.

++nick++ 02-10-2010 12:30 PM

Thanks all , that's a good explanation , was helpful to me

etech3 02-10-2010 12:41 PM

Thanks Chris

chrism01 02-10-2010 05:18 PM

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.