Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using nagios to read the file /var/spool/mail/root because i have some errors in email then know what is the problem.

I have setup the ownership to root:nagios.

but any time when root write to that file , then it changes the permission back to rw-------

i have to manually change it but again root changes it back

what should i do

share|improve this question
By "errors in email", do you mean problems with your email subsystem, or email that you have received about errors with some other subsystem? – MadHatter Jul 22 '13 at 8:41
@MadHatter . i am using amazon SES with sendmail . at Amazon i need to verify email before sending. sometimes if emails is not verified i get error mail in spool/root which says email address not verified so that i can know that there is error – MOtaro Site Jul 22 '13 at 8:49
up vote 2 down vote accepted

If I understand your comments correctly, you're getting emails from some automated system into root's local spool warning of errors with some other subsystem (email authentication), and you want NAGIOS to be able to look for those. Presumably, you've got or written some NAGIOS plugin that checks root's email spool for these; let's call it check_root_mbox.

The issue is ensuring that the plugin has the right permissions to read the mailbox file, which you've been trying to do by adjusting the ownership of root's mail spool file. That's probably not the best way to do this.

Either you need to run the plugin under sudo, or you need to modify the original jobs that generate these errors so that the replies come to somewhere other than root@localhost. The latter is beyond the scope of this answer, as you've told us nothing about the jobs that generate these bounces.

If you go for the former, it has two steps; running the plugin under sudo, and having sudo permit it.

To do the first part, if you're running under NRPE, put some line like

command[check_root_mbox]=sudo /usr/lib/nagios/plugins/check_root_mbox

in your nrpe.cfg, adjusting paths accordingly. If you're running NAGIOS on the system itself, put a check_command such as

define command{
        command_name    check_root_mbox
        command_line    /usr/bin/sudo $USER1$/check_root_mbox

in your config, and use it. Then for the second part, put a line like

nagios  ALL=(root) NOPASSWD: /usr/lib/nagios/plugins/check_root_mbox

in your sudoers file, again adjusting paths accordingly.

share|improve this answer
when u put /usr/lib... after NOPASSWD Does it mean that system will ask no password for that command but if nagios try to execute anything else with sudo then it will ask for password – MOtaro Site Jul 23 '13 at 1:08
Half-right; it means that nagios will be able to sudo that command without being prompted for a password, but that it won't be allowed to execute anything else via sudo no matter what password it provides. – MadHatter Jul 23 '13 at 5:39

Don't try it this way. Your SMTP server (whatever one you use) has diagnose commands that will tell you (and nagios) if there are problems. Reading a spool file is not a way to learn about the status of it.

share|improve this answer
i am using sendmail and maillog does not show me relevant error message. i am using amazon aws-email for sending emails via sendmail – MOtaro Site Jul 19 '13 at 6:28
Use check_smtp and maybe some specialized sendmail plugin. mailq should show you the state of the mail queue. – Sven Jul 19 '13 at 6:43

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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