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

Hey, thanks for your post. I looked in all three crontabs (current user, root, and www-data) but didn’t find any cron jobs at all. Pretty strange.

But on the other hand I’m not getting mail any more.

EDIT: I was wrong, I am still getting mail. Here is a sampling:

root@nextcloudpi:~# cat /var/spool/mail/root
From root@rpi4b  Sat Jul  6 00:00:13 2024
Return-Path: <root@rpi4b>
X-Original-To: root
Delivered-To: root@rpi4b
Received: by rpi4b (Postfix, from userid 0)
        id 0D95E2172; Sat,  6 Jul 2024 00:00:13 +0000 (UTC)
From: root@rpi4b (Cron Daemon)
To: root@rpi4b
Subject: Cron <root@nextcloudpi>  /bin/bash /usr/local/bin/freedns.sh
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20240706000013.0D95E2172@rpi4b>
Date: Sat,  6 Jul 2024 00:00:13 +0000 (UTC)

FreeDNS client started
https://freedns.afraid.org/dynamic/update.php?asdfasdfa
Registered IP: xxx | Current IP: xxx

From root@rpi4b  Sat Jul  6 00:30:08 2024
Return-Path: <root@rpi4b>
X-Original-To: root
Delivered-To: root@rpi4b
Received: by rpi4b (Postfix, from userid 0)
        id E6A78BAD; Sat,  6 Jul 2024 00:30:08 +0000 (UTC)
From: root@rpi4b (Cron Daemon)
To: root@rpi4b
Subject: Cron <root@nextcloudpi>  /bin/bash /usr/local/bin/freedns.sh
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
Message-Id: <20240706003008.E6A78BAD@rpi4b>
Date: Sat,  6 Jul 2024 00:30:08 +0000 (UTC)

FreeDNS client started
https://freedns.afraid.org/dynamic/update.php?asdfasdfasd
Registered IP: xxx | Current IP: xxx

However if I look in crontab -e as root, all I see are the instructions and an empty crontab.

I don’t use NextcloudPi myself, but now that I think of it again, there’s probably an option in the NextcloudPi admin interface where you can configure an actual email account to forward these messages to.

As for why you are receiving the messages in the first place, I can only guess, but it is probably because you have enabled the FreeDNS DynDNS service somewhere in the NextcloudPi admin interface. If you are not using the FreeDNS service, you may want to disable it in the admin interface, which should also stop the messages from beeing sent.

According to the code on Github, this particular cronjob is stored in /etc/cron.d/freeDNS. However, I think you should probably not just maually delete it, but as mentioned above, look for an option in the Nextcloud Pi settings that either forwards the notifications to a real email address or properly disables FreeDNS if you are not using it.

Hi, thanks a lot for your help, especially for finding where the cronjob was located.

I looked for where to setup email on https://docs.nextcloudpi.com/, but unfortunately the whole page disappears as soon as you type 3 letters into the search box. This probably deserves its own thread, but details are hidden

Here is a screenshot:


Documentation with 2 letters typed in search bar


Documentation website with 3 letters typed in search bar (mostly blank screen)

I do want to continue to get updates from freeDNS, but hopefully only when things go wrong, not every time. Currently it interrupts me if I’m typing at the terminal with “You have new mail in /var/mail/root” when I’m in the middle of a keystroke.

I found a reference for the WebUI configuration, and some of the other plugins like fail2ban support adding a personal email address for updates, but no global option, and no option in the freeDNS section.

I ended up editing /usr/local/bin/freeDNS.sh and commenting out every line that started with “echo” as a start. There is probably a better way to do this.