1

I'm running some cron jobs on my machine and every time I fire up a terminal session I'm getting a 'You have mail' message (the job produces output on success which gets mailed to me).

Any way to turn this notification off?

2 Answers 2

5

The exact mechanism depends on what shell is running in the "terminal session". For the BASH shell, the man page for "bash" says:

   MAILCHECK
          Specifies how often (in seconds)  bash  checks  for  mail.   The
          default  is  60 seconds.  When it is time to check for mail, the
          shell does so before displaying the  primary  prompt.   If  this
          variable  is  unset,  or  set  to  a  value that is not a number
          greater than or equal to zero, the shell disables mail checking.

so setting MAILCHECK=-1 in your .bashrc file would do it. Other shells have man pages with similar advice. (My bash 5.0.17 refuses to let me set the variable to a non-integer unless I first unset it, so the man page is incomplete about using "not a number".)

3
  • 1
    I would also recommend to read the emails with mail and see that you cronjobs will stop generating them.
    – Matteo
    Commented Jan 23, 2015 at 7:32
  • Awesome, thanks. Should have thought to check the man page for bash.
    – Peter Berg
    Commented Jan 23, 2015 at 18:41
  • 1
    Uh, hate to break it to you but setting MAILCHECK to zero actually DOES NOT disable mail check, not just on MY system but even according to the text cited in the answer. And I quote: "If this variable is unset, or set to a value that is not a number greater than or equal to zero, the shell disables mail checking." Last time I checked, zero IS a number that is "greater than or equal to zero", so mail checking is NOT disabled. Oopsie!
    – Richard T
    Commented Jul 9, 2022 at 23:53
2

Mail sent by cron is often considered a spam and called cram (cron spam). It is indeed not useful to receive notification every time command was run and succeeded but it would be good if cron still informed you about errors. You can cronic for this purpose:

Cronic is a small shim shell script for wrapping cron jobs so that cron 
only sends email when an error has occurred. Cronic defines an error as 
any non-trace error output or a non-zero result code.

(from http://habilis.net/cronic/)

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .