Friday, January 14, 2011

Disable crontab mail

By default, crontab on, for example, Debian, will mail any output of a job in your crontab to that user. How would one go about disabling this functionality?

  • There are two main ways of doing this, as I discovered.

    Either you set the MAILTO-variable to nothing at the start of the file:

    MAILTO=""
    

    or you redirect each cronjobs output to /dev/null:

    <command> > /dev/null
    

    The second having the advantage that output on stderr should still be mailed to you.

    Catherine MacInnes : If you want to also redirect stderr on a command by command basis just add '>> /dev/null' to the end of the second line.
    sleske : The second solution is much better, because that way you are still notified of any problems in crontab scripts.
    Saurabh Barjatiya : >> will append data of stdout to file. It cannot be used to redirect stderr. Use 2> to redirect stderr.
  • To prevent output of both stdout and stderr use the following syntax:

    <command> > /dev/null 2>&1
    

0 comments:

Post a Comment