You have new mail warning when starting the shell


Each time I login to the shell I can see a little message telling me ‘You have new mail’:

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
You have new mail.
 DietPi v6.28.0 : 21:44 - Do 12.03.2020

I checked the directory “/var/mail” and in fact there is a file called “root” slowly growing. It has many entries of the following content:

From Thu Mar 12 16:26:25 2020
Received: from root (uid 0)
	id 1e90a
	by DietPi (DragonFly Mail Agent v0.11);
	Thu, 12 Mar 2020 16:26:25 +0100
From: root (Cron Daemon)
To: root
Subject: Cron <root@DietPi> /usr/sbin/logrotate /etc/pihole/logrotate (failed)
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>
Date: Thu, 12 Mar 2020 16:26:25 +0100
Message-Id: <5e6a54a1.1e90a.2672a8a0@DietPi>

/bin/sh: 1: /usr/sbin/logrotate: not found

It seems to be related to cron, logrotate and/or pihole?! But I’m not sure what to do or where to search further. Can someone help me? I can’t find an according command with crobtab -l. What is creating this mail?

I installed dma as a mailing program a while ago and it works great. But seems there is a side effect hehe

Cron sends mails automatically about failing cron jobs, if an mta is found. It seems like there is a cron job from or for Pi-hole to rotate its log file, but this is obsolete on DietPi due to ramlog and without logrotate being installed by default.

Please check the following:

which logrotate
grep logrotate /etc/cron.*/*

And if you want to get rid of any cron mails, add MAILTO="" as new line to the top of /etc/crontab.

For v6.29 I added an option to dietpi-cron to set this setting, and by default it will be disabled (no cron mails).

Found it, in /etc/cron.d/pihole remove the line that contains logrotate.

I’ll open a PR to either remove or in Pi-hole upstream (they serve a regular logrotate config, no need to run it manually IMO) or add a check if the command or available before calling it.

Thank you very much for your prompt reply and help! It worked. :slight_smile: And sorry for the late answer, my attention was distracted by that China virus :confused:

Just one (minor) issue left: The email that was sent (because of that logrotate cronjob) was completely blank. So, emailing itself seemed to work but not putting content in the mail?! Maybe that is something you like to know? I use dma as mta.

AFAIK the content of the mail depends on the script. Generally by default cron sends an email if the executed script/command exits with an error code. It then should contain the output that was send to STDERR output stream, and that might be hidden/redirected to /dev/null.

New info on the issue: pi-hole 5.0, a new major release, has been released. It appears that it added the logrotate command again to the cron-file and causes an email to be sent. Maybe you like to open a PR again there? :slight_smile: