3

I'm trying to set up mailx on my server. On one server (Raspbian) I am informed of new mail with a message You have new mail (or something similar). On another machine (Raspbmc), I never have this notification.

On both machines, ~/.bashrc is essentially identical. /etc/mail.rc doesn't exist on the latter system, but it does on the former, with the following content.

set ask askcc append dot save crt
ignore Received Message-Id Resent-Message-Id Status Mail-From Return-Path Via Delivered-To

EDIT

I should also mention that I'm connecting via SSH.

As implied here, I tried copying /etc/pam.d/sshd from the working Raspbian server to the broken Raspbmc server, and logging out and back in, but it didn't fix the problem. This file contains

# Print the status of the user's mailbox upon successful login.
session    optional     pam_mail.so standard noenv # [1]

Finally, I've also confirmed that the access time of /var/mail/pi is earlier than the modification time. (The filesystem is mounted with noatime anyway.)

3

AFAIK mail notification is a shell function, in bash by setting the MAIL environment variable and it has little to nothing to do with the mailx command. In a different shell it may function differently.

In my RHEL system it is configured in /etc/profile with MAIL="/var/spool/mail/$USER"

A simple echo $MAIL will show if it is set or not.

At first glance it only works with mbox style mailboxes and not with Maildir where each message is stored in a separate file.

From the bash manual page:

   MAIL   If  this  parameter is set to a file name and the MAILPATH vari-
          able is not set, bash informs the user of the arrival of mail in
          the specified file.
   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.
   MAILPATH
          A colon-separated list of file names to  be  checked  for  mail.
          The message to be printed when mail arrives in a particular file
          may be specified by separating the file name  from  the  message
          with a '?'.  When used in the text of the message, $_ expands to
          the name of the current mailfile.  Example:
          MAILPATH='/var/mail/bfox?"You  have  mail":~/shell-mail?"$_  has
          mail!"'
          Bash  supplies  a default value for this variable, but the loca-
          tion of the user mail files that it  uses  is  system  dependent
          (e.g., /var/mail/$USER).

In the csh manual on that same system it seems lower case

The mail shell variable can be set to check for new mail periodically.

and

   mail    The names of the files or directories  to  check  for  incoming
           mail,  separated  by  whitespace,  and optionally preceded by a
           numeric word.  Before each prompt, if 10  minutes  have  passed
           since  the last check, the shell checks each file and says 'You
           have new mail.' (or, if mail contains multiple files, 'You have
           new  mail  in  name.')  if the filesize is greater than zero in
           size and has a modification time greater than its access  time.

           If  you  are  in  a  login shell, then no mail file is reported
           unless it has been  modified  after  the  time  the  shell  has
           started  up,  to  prevent  redundant notifications.  Most login
           programs will tell you whether or not you have  mail  when  you
           log in.
  • Great! FWIW I'm not sure where it's set in Raspbian; I tried grepping in a few places, but didn't find anything. grep MAIL -r /etc/profile /etc/profile.d/ /etc/bash.bashrc ~/.profile ~/.bashrc /etc/environment ~/.bash_history Anyway, I put export MAIL='/var/mail/pi' in the Raspbmc's ~/.bashrc and it works fine. – Sparhawk Jul 14 '14 at 1:29
  • Related question here, regarding finding where MAIL is set: unix.stackexchange.com/questions/144415/… – Sparhawk Jul 14 '14 at 10:42
  • Sorry, I'm going to have to unaccept this answer, as it's not working for me. Despite my comment above, I can't exactly remember if it worked properly before or not. I still don't get any kind of "new mail" notification. Also, I'm not sure if it's important, but I log in via SSH. – Sparhawk Jul 26 '14 at 5:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.