Possible to disable "You have new mail in /var/mail/root"?

Solution 1:

Those messages are probably periodic reports. It's quite common to set daily_show_success=NO in /etc/periodic.conf so it doesn't generate "all's good" messages. Also, daily_output="$destination" should be set to your e-mail address or a log file that you can monitor. The same can be set for weekly_ and monthly_ - and probably should be.

You can delete those e-mails by starting mail, d * to delete all messages, and q to quit.

Disabling the mail check is usually a mistake. If a daemon is configured incorrectly to deliver mail to the local root, you want to know, it might have something important to say and you'll miss those messages if you disable the mailcheck.

Solution 2:

In addition to Dennis' answer, FreeBSD sets the MAIL environment variable for all users in the default login class. This is in /etc/login.conf.

You can change this in several ways:

  1. Edit /etc/login.conf and remove MAIL=/var/mail/$ from the setenv line. You then need to compile the login database by running cap_mkdb /etc/login.conf.

  2. Create a new login class that just applies to you, or a group of users. Set this for each user by using pw usermod <username> -L <class>.

  3. Create a user-specific ~/.login.conf. This file should have a record called me. This can override a subset of the global settings. Likewise this file needs to be compiled with cap_mkdb.

See login.conf(5) for more information on the login capabilities database.


Solution 3:

That should take care of that message for root logins. If you're logging in as another user, you'll need to add that to the ~/.bashrc of each user you want to disable it for. Or you can put it in the central startup file: /etc/profile to have it take effect for all users.

You will need to check to see if MAILCHECK is being set at a later point in the startup file sequence overriding your unset.

Note that the startup files are processed as follows (from the Bash Manual) (emphasis mine):

Invoked as an interactive login shell, or with --login

When Bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.

When a login shell exits, Bash reads and executes commands from the file ~/.bash_logout, if it exists. Invoked as an interactive non-login shell

When an interactive shell that is not a login shell is started, Bash reads and executes commands from ~/.bashrc, if that file exists. This may be inhibited by using the --norc option. The --rcfile file option will force Bash to read and execute commands from file instead of ~/.bashrc.

So, typically, your ~/.bash_profile contains the line

if [ -f ~/.bashrc ]; then . ~/.bashrc; fi

after (or before) any login-specific initializations.

Tags:

Bash

Freebsd