Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I set up a crontab in Cpanel to run every min. It's working great but I don't want an e-mail every min. I have a second cron tab that runs every day. I would like the responce of this tab. Is there a way to tell the crontab to be silent or only e-mail on error?

I have:

    *    *  *   *   * php /home/public_html/folder/file.php 2>&1

The last bit 2>&1 I added because i thought it would make it silent.

From the Cpanel Docs:

You can have cron send an email everytime it runs a command. If you do not want an email to be sent for an individual cron job you can redirect the command's output to /dev/null like this: mycommand >/dev/null 2>&1

share|improve this question

3 Answers 3

up vote 1 down vote accepted

use -q it means "quiet" and thus doesn't generate output

*    *  *   *   * php -q /home/public_html/folder/file.php

also, ask yourself why you want to run it every minute, that's a little excessive.

share|improve this answer
    
It's a crontab that checks the status of buses in real time. The file is checking to see how many minutes the bus is away and if it's close alerts the user. –  BandonRandon Dec 23 '10 at 22:03
    
Also, -q did the trick. –  BandonRandon Dec 23 '10 at 22:14
    
If it needs to run once a minute, what's the problem with that? Surely the developer knows why it needs to run so frequently... –  Tom O'Connor Dec 23 '10 at 23:05
    
@Tom generally cron may not be the right solution for things that need to run that often. But that's an opinion, and one that we enforce at work. –  xenoterracide Dec 24 '10 at 2:19
    
@xenoterracide what are some other options to check a database and sent out alerts on a realtime basis? –  BandonRandon Apr 6 '11 at 5:37

2>&1 redirects the everything written to stderr to stdout

>/dev/null redirects stdout to /dev/null

cron will always email you anything sent to stdout or stderr unless redirected elsewhere. Ideally, your PHP script should be rewritten to accept a --quiet flag that doesn't write a whole bunch of useless crap out to stdout, which you could then use in your cron job.

The lazy man's option is to put a wrapper script around your cron job that will stop it from emailing you unless your command exits non-zero.

share|improve this answer

The correct setup would be

>/dev/null

This makes the standard output be ignored and only emails you if there is an error

Your current setup doesn't handle the standard output therefore you get an email every time it runs.

share|improve this answer
    
You're assuming that errors are being printed to stderr rather than stdout. This is not a safe assumption. –  rodjek Dec 23 '10 at 21:42
    
I see. I also see that curl has --silient but can I curl an php script? –  BandonRandon Dec 23 '10 at 21:43
    
@BandonRandon, you can curl URLs like http/https if this was your question. –  Istvan Dec 23 '10 at 21:55
    
@l1x yes that was my question. That would make it run just like loading it in the browser correct? –  BandonRandon Dec 23 '10 at 22:07
    
@BandonRandon yes, like yourdoma.in/folder/file.php –  Istvan Dec 23 '10 at 22:10

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.