1

What dose mean dev/null and dev/null 2>&1 ? if i run php -q /http/get_pdf.php

sorry for my short question when we run this file from url it will create a .pdf file and mail, we are looking to send a mail using cron in that case we need to run one pdf report for one time.

suppose goto url https://example.com/get_pdf.php it will ask me mail id once we add mail id it will generate report what you ask for from drop down manu like what is sale for week? it will be mail on mail id, we don't want to from url we want happend from cron. Can same pls help me.

neolix
  • 518
  • 7
  • 20

3 Answers3

5

I'm assuming you're looking for the difference between something like this:

$ php -q /http/get_pdf.php > /dev/null

and this:

$ php -q /http/get_pdf.php > /dev/null 2>&1

The first version redirects stdout to /dev/null, and the second redirects both stdout and stderr to /dev/null.

EEAA
  • 108,414
  • 18
  • 172
  • 242
  • yes but same time i need to out to mail bcoz that get_pdf.php will create a .pdf file as report in one of the folder that i need to mail that pdf using cron – neolix Aug 27 '10 at 15:54
  • Well technically the `2>&1` redirects stderr to stdout, which is redirected by the `> /dev/null` part. But yes, they both end up going to the bit-bucket. – Chris S Sep 09 '10 at 12:40
1

When you have a command like:

COMMAND > /dev/null 2>&1

The "> /dev/null" part says to redirect all Standard Output from the command to the bit bucket. The "2>&1" part says redirect all Standard Error to Standard Out (which in turn gets redirect to /dev/null)

So essentially that will suppress all output.

Safado
  • 4,726
  • 7
  • 35
  • 53
1

You mean something like /command >/dev/null 2>&1?

  • /command: will be run
  • >/dev/null: redirect standard output to nothing (/dev/null is a special null device, that means no output will be shown)
  • 2>&1: redirect errors to stdout.

If you are running this as cron, stdout is often a mail (if errors occurs, mail to administrator)

Lekensteyn
  • 6,111
  • 6
  • 37
  • 55
  • yes i want to run as cron thanks for your quick reply how do run in cron can send me step pls. thanks in advance!! – neolix Aug 27 '10 at 15:52
  • This is basically universal syntax for stdout and stderr redirection. I have been quite surprised it works in not only every Unix/Linux variant I use (not so surprising), but Windows. That is universal, haha. – songei2f Aug 27 '10 at 15:55