[SOLVED] - There is mail, but mail command reports "No mail for root"

Issues related to applications and software problems
Post Reply
User avatar
warron.french
Posts: 560
Joined: 2014/03/27 20:21:58

[SOLVED] - There is mail, but mail command reports "No mail for root"

Post by warron.french » 2021/01/28 19:49:52

I have several cronjobs that are creating mail messages being sent to root.
I know this is true because the size of the /var/spool/mail/root file is large.

If I am sitting at the shell as root, and I simply type:

Code: Select all

mail
The response is:
No mail for root

Knowing that there are mail messages in /var/spool/mail/root I used the command:

Code: Select all

mail -u root
This did work.

I used to be able to simply type the mail command before my server's recent rebuild. What can I do to restore this level of ease
(simply typing: mail)?

Do I just need to set the MAIL variable in /root/.bash_profile ?
Last edited by warron.french on 2021/01/29 00:42:34, edited 1 time in total.
Thanks,
War

User avatar
TrevorH
Forum Moderator
Posts: 30314
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: There is mail, but mail command reports "No mail for root"

Post by TrevorH » 2021/01/28 21:22:39

How did you become root?
CentOS 6 died in November 2020 - migrate to a new version!
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 is dead, do not use it.
Full time Geek, part time moderator. Use the FAQ Luke

User avatar
warron.french
Posts: 560
Joined: 2014/03/27 20:21:58

Re: There is mail, but mail command reports "No mail for root"

Post by warron.french » 2021/01/28 21:51:25

Since this latest build, auto-hardened by our vendor, I can only execute:
sudo bash

This tells me that the problem is the MAIL variable is still set to the account of the person/identity executing "sudo bash."
Thanks,
War

User avatar
TrevorH
Forum Moderator
Posts: 30314
Joined: 2009/09/24 10:40:56
Location: Brighton, UK

Re: There is mail, but mail command reports "No mail for root"

Post by TrevorH » 2021/01/28 22:14:29

Yes, that's why.

You need to use sudo su - to get a login shell that does not inherit the parent's environment (i.e. $HOME is set correctly etc).
CentOS 6 died in November 2020 - migrate to a new version!
Info for USB installs on http://wiki.centos.org/HowTos/InstallFromUSBkey
CentOS 5 is dead, do not use it.
Full time Geek, part time moderator. Use the FAQ Luke

User avatar
warron.french
Posts: 560
Joined: 2014/03/27 20:21:58

Re: There is mail, but mail command reports "No mail for root"

Post by warron.french » 2021/01/29 00:41:35

Thanks TrevorH,
I am going to stick to the mail -u root command.

Thanks for the validation.
Thanks,
War

Post Reply

Return to “CentOS 7 - Software Support”