Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I have Nagios running on a webserver. For this one Nagios service check in particular, if it fails, it will run a script. This script is triggered via Nagios event handlers.

Nagios event handler command:

define command{
        command_name    testDisableServer
        command_line    /usr/local/nagios/etc/objects/event_handlers/testDisableServer.sh
}

I am executing a script called testDisableServer.sh from Nagios event handlers that looks like this:

#!/bin/bash
wall "Script execution started";
/usr/bin/sudo /root/scripts/disableServer.sh force

This script 'testDisableServer.sh' has the following permissions:

-rwxr-xr-x 1 nagios nagios 2.0K Oct 12 14:57 testDisableServer.sh

When the service goes down, I will get a wall post in my SSH connection saying "Script execution started", but it will not trigger my disableServer.sh script. I tried to place another wall post inside of disableServer.sh and it did not trigger it.

This script is being run by the user 'nagios'. 'nagios' was added in visudo, as such:

nagios  ALL=(ALL)NOPASSWD:/root/scripts/disableServer.sh

Running this script as the user 'nagios' from a command line works perfectly fine. However, when the event handler triggers it, there is no output. I tried to catch the output into a log file, and I came up with nothing. These are the permissions on /root/scripts/disableServer.sh:

-rwxr-xr-x   1 root root 2.0K Oct 12 15:01 disableServer.sh

Why would the event handler hit 'testDisableServer.sh', but not execute 'disableServer.sh' from a Nagios event handler, but work just fine in an SSH connection as the user nagios? BTW, 'testDisableServer.sh' is just an extra layer added to see if the event handlers were working, which they seem to be. This will be removed after this script execution is all sorted out.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Possibly it's an environment issue (the script is relying on something in its environment that is not available when run by nagios).

I would change your script (temporarily for debugging only) to:

#!/bin/bash
exec 2> /tmp/log."$$"
set -x
wall "Script execution started";
/usr/bin/sudo /root/scripts/disableServer.sh force

And add another set -x at the top of disableServer.sh

To see what's going on (in the /tmp/log.* files).

share|improve this answer
    
You just saved my life. Thank you so much. The log file said this: 'sudo: sorry, you must have a tty to run sudo' So after a quick Google search, I had to comment out this line in sudoers: Defaults requiretty Is there any major security implication for commenting this out that I can't think of off of the top of my head? –  Ryan Oct 12 '12 at 20:16
    
That question has been asked on superuser and serverfault but nobody has come up with a good answer/reason for why that requiretty was added to the default configuration by RedHat. All the reasons I've seen mentionned don't hold up. –  Stéphane Chazelas Oct 12 '12 at 20:57

Your Answer

 
discard

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.