Ubuntu – Who is telling me “You have mail”

bashemailmotdssh

On a server running Ubuntu 14.04 I see You have new mail in the motd every time I log in via SSH.

Q: Who is telling me this?

Mail does not find anything, and I do not expect any mails on this server.

crontab for "me" and "root" contains MAILTO="" .

The text You have new mail is not present in /etc/motd or /var/run/motd.

Some commands I hope are relevant:

me@AtomServer:~$mail
No mail for me
me@AtomServer:~$sudo mail
No mail for root
me@AtomServer:~$sudo ls -l /var/mail
total 8
-rw------- 1 la   mail 1 Jul 15 22:12 me
-rw------- 1 root mail 1 Jul 27 19:59 root
me@AtomServer:~$

me@AtomServer:~$grep '^s.*motd' /etc/pam.d/sshd
session    optional     pam_motd.so # [1]
me@AtomServer:~$$ls -la /etc/update-motd.d
total 48
drwxr-xr-x   2 root root  4096 May 13 13:38 .
drwxr-xr-x 127 root root 12288 Jul 27 20:06 ..
-rwxr-xr-x   1 root root  1220 Apr 19  2012 00-header
-rwxr-xr-x   1 root root  1358 Apr 19  2012 10-help-text
lrwxrwxrwx   1 root root    46 Jan 30 21:57 50-landscape-sysinfo -> /usr/share/landscape/landscape-sysinfo.wrapper
-rwxr-xr-x   1 root root   149 Aug 22  2011 90-updates-available
-rwxr-xr-x   1 root root   129 Sep 30  2011 91-release-upgrade
-rwxr-xr-x   1 root root   129 Jun 16  2014 95-hwe-eol
-rwxr-xr-x   1 root root   142 Aug 22  2011 98-fsck-at-reboot
-rwxr-xr-x   1 root root   144 Aug 22  2011 98-reboot-required
-rwxr-xr-x   1 root root  1158 Apr 19  2012 99-footer
 me@AtomServer:~$

me@AtomServer:/etc/update-motd.d$grep -ri 'mail' *
me@AtomServer:/etc/update-motd.d$

/etc/motd.tail does not exist.

Best Answer

Well, this is being done your shell itself. Apparently it is monitoring the file (or directory) pointed by the MAIL (or MAILPATH) environment variable.

This is documented in man bash :

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

On a different note the contents of motd is actually governed by the PAM module pam_motd (the shell might have something to add though as per user configuration files).

By default pam_motd shows the static content of the /etc/motd file along with the dynamic outputs generated from running scripts in the /etc/update-motd.d directory (using run-parts).

Related Question