You have new mail in /var/mail/root -- NCP

Hi, I recently installed NCP and I’m trying to learn its ins and outs.

Whenever I am doing something as root, I often get interrupted mid-keystroke with “You have new mail in /var/mail/root”.

I looked at the mail, per these instructions, and it was mostly updates from cron about updating FreeDNS and lists of CVE vulnerabilities from daemon

I’m still learning how to be my own sysadmin. None of these messages are that interesting to me. How is it recommended to solve the problem of annoying mail in root? Something like:

  • redirect the routine mail to some kind of log that logrotates?
  • disable the “you have new mail” message and let it manage itself?
  • something else?

Any advice is appreciated! Thanks!

You probably can’t say there is a “best” way to do it.

If the function you are calling, provides a way to set a log level that you can then set to your needs.

In case of errors, it depends on you if you prefer to be notified by mail, or if you e.g. observer logfiles (like logwatch, logcheck, …). In that case, perhaps the process already write logs independently, then you could just silence the cron output.

Ideally, to manage to get just the log messages you need, not too many to be bombarded with noise, but not too few to miss important things.

1 Like

You could open the crontab of the user where these cronjobs are set…

For root, respectively the current user:

crontab -e

For another user like e.g. www-data

crontab -u www-data -e

…and then look for the following line:

MAILTO=root

and either comment it out or delete it:

#MAILTO=root

or set it to an empty string:

MAILTO=""

It’s also possible that the cron job itself contains a redirect to mail:

Example:

* * * * * /usr/bin/script.sh 2>&1 | mail -s "subject" root

In that case you could just remove the redirect.

However, you’d probably still want to send the ouput somewhere, for example to a file or to syslog: https://www.baeldung.com/linux/cron-job-redirect-output-stdout

1 Like