What is the usefulness of /dev/null 2>&1 in Cron?

Discussion in 'Server Operation' started by Shine, Mar 7, 2013.

  1. Shine

    Shine New Member

    For instance,
    if I have a .pl script, or .php script, I could simply execute on my terminal
    ]# php /path/to/my/script.php
    and make the code executed.

    So, adding a cron job to run every 5 minutes for this script, can be written like this:
    5 * * * * php /path/to/my/script.php
    And the question is:
    what is the difference between that statement, and, say:
    5 * * * * /usr/bin/php /path/to/my/script.php > /dev/null 2>&1
    I've searched the web for a detailed explanation but, I cannot find anything.
    Would you explain me this please?
    Or show me a page with this issue.

    Thanks a lot.
    Last edited: Mar 7, 2013
  2. TiTex

    TiTex Member

    as far as i know this redirects ( > ) any output from script.php to /dev/null ... which is nowhere (like a black hole) , and stderr ( 2 ) is redirected to ( >&1 ) stdout which is already redirected to nowhere , basicly it makes your script run silently and doesn't generate any output or error log/file

    i hope i'm not mistaken

Share This Page