No hint "You have new mail"

Normally I get the hint “You have new mail”, when I log in and there are new mails in /var/mail for my account (bash shell). But not with DietPi v6.33.3 (running on a ZeroPi).

I’ve set in my /etc/bash.bashrc the follwing environment variables:

MAILCHECK=60
MAIL=/var/mail

In /etc/pam.d/login there is a line:

session    optional   pam_mail.so standard

In Raspbian Buster this is enough to get the above mentioned hint. Why doesn’t it work in DietPi?

Hi,

can you give some hint what kind of mail you are expecting?

Thanks for your reply.

I do not expect any mail. The mail is already sitting in /var/mail. I just want the bash shell to give me a notification, when I log in.

Under Raspbian-Buster I get this notification, but not with DietPi. Both use the same configurations in /etc/bash.bashrc and /etc/pam.d/login (see my original post).

What configuration and/or package do I need, to get the same behaviour as in Raspbian-Buster?

still I don’t get what mails you are expecting to see. Quite confusing that you don’t expect a mail but you are looking for a mail notification. DietPi is a diet version of Raspberry OS with reduced amount of packages. Probably this functionality is not availably as the package was removed.

Maybe MichaIng knows what you are looking for

If you don’t understand my problem, you should read the bash man page (especially the chapter about the environment variables MAIL and MAILCHECK).

MAIL
If this parameter is set to a file or directory name and the MAILPATH variable is not set, bash informs the user of the arrival of mail in the specified file or Maildir-format directory.
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.

The above mentioned environment variables are correctly set and pam loads the module pam_mail.so, but the bash shell does not behave as expected (as it does with Raspbian-Buster). I think, something is broken or missing in DietPi.

When you login, can you verify that those two variables are set correctly, and that MAILPATH is not set:

echo $MAIL $MAILCHECK
echo $MAILPATH

And can you try to export those two variables instead on just assigning them:

export MAILCHECK=60
export MAIL=/var/mail

And is it assured that you actually did get mails present in /var/mail/$USER?

Finally, I cannot see it being a systemd-logind feature, but if above is all fine, try this:

systemctl unmask systemd-logind
apt install libpam-systemd
systemctl enable --now systemd-logind

Thanks for your reply.

The environment variables MAIL, MAILCHECK and MAILPATH are set as you described.

This is the output of ‘ls -l /var/mail’:

-rw------- 1 dgs mail 21748 13.02.2021 04:18:03 dgs

This is the output of ‘systemctl status systemd-logind.service’:

● systemd-logind.service - Login Service
   Loaded: loaded (/lib/systemd/system/systemd-logind.service; static; vendor preset: enabled)
   Active: active (running) since Mon 2021-01-04 21:38:21 CET; 1 months 9 days ago
     Docs: man:systemd-logind.service(8)
           man:logind.conf(5)
           https://www.freedesktop.org/wiki/Software/systemd/logind
           https://www.freedesktop.org/wiki/Software/systemd/multiseat
 Main PID: 20441 (systemd-logind)
   Status: "Processing requests..."
    Tasks: 1 (limit: 908)
   Memory: 1.0M
   CGroup: /system.slice/systemd-logind.service
           └─20441 /lib/systemd/systemd-logind

Jan 04 21:38:21 dpi systemd[1]: Starting Login Service...
Jan 04 21:38:21 dpi systemd-logind[20441]: New seat seat0.
Jan 04 21:38:21 dpi systemd-logind[20441]: Watching system buttons on /dev/input/event0 (r_gpio_keys)
Jan 04 21:38:21 dpi systemd[1]: Started Login Service.

The package libpam-systemd is not installed. I’ll give it a try and report.

Furthermore I noticed, that on login the content of /etc/issue[.net] is not shown on console. With Raspbian-Buster I see on login:

Linux rpi 4.19.66-v7+ #1253 SMP Thu Aug 15 11:49:46 BST 2019 armv7l
No mail.
Last login: Fri Feb 12 18:38:51 2021 from 10.91.25.13

With DietPi the first output line after the ssh command is the command prompt of the remote host. Maybe it’s related to the missing “You have new mail” message.

Ah lol, probably it’s simply overwritten/moved up by the login banner. Did you try to scroll up to see if the mail hint is shown above the DietPi banner?

/etc/issue[.net] are btw not shown “after” the login, but before the login credentials prompt. On boot, we have an own login prompt which is printed after /etc/issue print. It’s on the list to merge this, so that the little extra info are added/updated in /etc/issue itself. However, on a new login prompt, like a dedicated TTY or logging out from console, /etc/issue is shown as expected.

/etc/motd is what is shown after login, but it’s moved up into scroll buffer by the DietPi banner. Probably we should find a way to do it the other way round, print DietPi-Banner first and /etc/motd (+ other info like mail hints) afterwards, or merge our banner into /etc/motd, if it supports colour codes :thinking:.

I’ve installed libpam-systemd, but it didn’t change anything. I get no hint “You have new mail”.

During the last days I created on a new sdcard a plain vanilla armbian system. Et voilà : I get the hint “You have new mail”.

I suppose, that the DietPi configuration on top of the armbian system has broken this regulary behaviour.

Regarding the /etc/issue[.net] issue I noticed, that DietPi uses dropbear as SSH server, while Raspbian-Buster uses OpenSSH. In DietPi’s dropbear configuration the output of /etc/issue[.net] was disabled. That’s the reason for the different behaviour.

you can switch to OpenSSH Server as well using dietpi-software and adjust SSH server preference according your need

Yes, I can, but that doesn’t solve my problem with No hint “You have new mail”

Nevertheless, thanks for your reply.

For now I shall continue my configuration of the ZeroPi with plain vanilla armbian.

Neither OpenSSH, nor Dropbear show /etc/issue(.net) by default:

The default configs provided by Debian (which we do not touch in this regards) do not change this. I guess it is seen as information leak which must be disabled until the admin manually changes it.

In case of Dropbear: /etc/default/dropbear contain the DROPBEAR_BANNER option which allows to define a banner file.
In case of OpenSSH: /etc/ssh/sshd_config has the Banner option to do so.

[hr]
/etc/motd on OpenSSH is controlled by the PrintMotd option in /etc/ssh/sshd_config, which defaults to “yes”: https://manpages.debian.org/buster/openssh-server/sshd_config.5.en.html#PrintMotd_2
But this option is overwritten by the official Debian openssh-server package’s /etc/ssh/sshd_config to PrintMotd no, and hence on DietPi since we do not touch this setting.

In case of Dropbear, /etc/motd is printed by default, unless the -m option is passed or it is disabled at compile time. Even without printing the DietPi banner, I cannot see /etc/motd, even that neither the “-m” flag is passed, nor can I find a compile time option in the Debian build logs that would actively disable it. But I found an interesting upstream changelog: https://github.com/mkj/dropbear/blob/master/CHANGES#L81
That is from 2020.79, hence newer than what Debian Buster ships. Tested on Debian Bullseye, and voila:

Using username "root".
Authenticating with public key "Micha-20200711"

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.
 ─────────────────────────────────────────────────────
 DietPi v7.0.-1 (dev) : 16:11 - Tue 02/23/21
 ─────────────────────────────────────────────────────
 - FQDN/hostname : VM-Bullseye
 - LAN IP : 192.168.1.23 (eth0)
 - Freespace (RootFS) : 6.9G
 - MOTD : Please help testing DietPi beta v7.0.0:
          https://github.com/MichaIng/DietPi/issues/4121
 ─────────────────────────────────────────────────────

 DietPi Team     : MichaIng (lead), Daniel Knight (founder), Joulinar (support)
 Image           : DietPi Core Team (pre-image: Debian mini.iso)
 Web             : https://dietpi.com | https://twitter.com/DietPi_
 Patreon Legends : Camry2731
 Donate          : https://dietpi.com/#donate
 DietPi Hosting  : Powered by https://myvirtualserver.com

2021-02-23 16:11:25 root@VM-Bullseye:~#

Since there is no option to explicitly enable /etc/motd on Dropbear, if it is required, OpenSSH would need to be used on Debian Buster, and the default configuration file adjusted as mentioned above.

[hr]
That the /etc/motd and likely the mail hints are printed before the DietPi banner, and hence moved into scrollback buffer, is indeed an issue. Three solutions I can think of:

  1. Integrating those into the DietPi banner, which means that we would need to maintain a set of possible bash/shell prints.
  2. Integrating the DietPi banner into /etc/motd, which means that we need to dynamically update that file.
  3. Do not move the current screen content into the scrollback buffer when printing the DietPi banner, which means that the screen after login still contains the /etc/issue(.net) (when enabled on SSH server), login prompt + input, /etc/motd (when not disabled on SSH server) and then the DietPi banner. This would be the easiest solution, but it’s probably user-preference. We could make it an option in the dietpi-banner menu :thinking:.

Barney
If you still run the DietPi system, it would be great to know whether the assumption is right that the mail hint is indeed printed before the DietPi banner, and hence can be seen when scolling up after SSH login, similar like the SSH login prompt + /etc/motd output in my paste above.

Your assumption is false. The mail hint is not printed before the DietPi banner.

This is the output of the DietPi login (the DietPi banner is disabled):

ssh dpi
Weitere User im System:
dgs      pts/0        Feb 23 16:06 (10.91.25.13)
dgs      pts/1        Feb 23 16:06 (10.91.25.13)
dgs      pts/2        Feb 23 16:07 (10.91.25.13)
dgs      pts/4        Feb 23 18:51 (10.91.25.13)
root     pts/3        Feb 23 16:09 (10.91.25.13)

This is the output of the Armbian login:

ssh azp
 _____              ____  _ 
|__  /___ _ __ ___ |  _ \(_)
  / // _ \ '__/ _ \| |_) | |
 / /|  __/ | | (_) |  __/| |
/____\___|_|  \___/|_|   |_|
                            
Welcome to Armbian 21.02.2 Buster with Linux 5.10.16-sunxi

System load:   2%           	Up time:       4 days 23:41		Local users:   4            	
Memory usage:  20% of 491M   	IP:            10.91.25.33
CPU temp:      34°C           	Usage of /:    17% of 5.0G   	

[ General system configuration (beta): armbian-config ]

You have new mail.
Last login: Tue Feb 23 15:57:06 2021 from 10.91.25.13
Weitere User im System:
dgs      pts/1        2021-02-23 15:55 (10.91.25.13)
dgs      pts/2        2021-02-23 15:55 (10.91.25.13)
dgs      pts/3        2021-02-23 15:57 (10.91.25.13)
dgs      pts/4        2021-02-23 18:58 (10.91.25.13)
root     pts/0        2021-02-23 12:59 (10.91.25.13)

With Armbian there is the mail hint and the ‘last login’ message. Both don’t appear with DietPi.

The “last login” message is not from the shell but from OpenSSH and as such it shows up very well on DietPi when switching to OpenSSH.

Btw, if you’re expecting mails from failing cron jobs, note that for system cron jobs in /etc/cron.hourly/daily/… we disabled mails by default since most users will only see “(CRON) info (No MTA installed, discarding output)” in their syslog. Use dietpi-cron or sed -i ‘/MAILTO/d’ /etc/crontab to enable it.

I enabled cron mails, created a minutely failing dummy cron job and installed sendmail. The two variables are now set automatically, nothing to do manually. /var/mail/root gets the cron job failure messages, but I still couldn’t see the new mails message on SSH login. Then I switched to OpenSSH, and got a new mails message right after the install has finished:

 DietPi-Software
─────────────────────────────────────────────────────
 Mode: Installation completed

[ SUB1 ] DietPi-Services > restart
[  OK  ] DietPi-Services | restart : cron
[ INFO ] DietPi-Software | Starting installed services, not controlled by DietPi-Services
[  OK  ] DietPi-Software | systemctl start ssh
You have new mail in /var/mail

and then as well on new SSH logins and on local console login, but the slightly shorter version “You have new mail.”. Switched back to Dropbear, messages on SSH logins are gone, messages on local console stay, of course.

But while playing around, I see the mail messages on Dropbear as well, just not directly on login, instead when the first full minute has been reached, as part of the command prompt, when a cron job has failed and the MAILCHECK interval reached:

2021-02-24 01:44:53 root@VM-Bullseye:~#
2021-02-24 01:44:57 root@VM-Bullseye:~#
You have new mail in /var/mail
2021-02-24 01:45:02 root@VM-Bullseye:~#

Okay I think I got it:

  • bash mail check works fine, but it does not print anything on login, but instead as part of the following command prompts, when new mails arrive AFTER login/the shell session started.
  • A direct notification about new mails on login seems to be a console/terminal feature, which is supported by OpenSSH and by login (local console), which explains why the text is different/shorter compared to the bash+OpenSSH one, but not by Dropbear.

So it’s mostly about Dropbear vs OpenSSH here :slight_smile:.