I created a simple script for nagios to check a port on a remote server. Originally, I tried to use lsof
.
#!/bin/bash
RESULT=$(lsof -i :8080 | grep LISTEN)
if [ -n "$RESULT" ]
then
echo "$RESULT"
exit 0
else
echo "Check application port is down"
exit 2
fi
On the local machine, the nagios user could run and execute the script and get the expected output. But remotely, using check_nrpe
, I always got the else echo back
Check application port is down
Even though as I said running the script locally it worked properly
The nrpe user had all rights needed to execute the script, SELinux was in permissive mode, but I could never get it to work. So I changed the RESULT line to use netstat
.
RESULT=$(netstat -anp | grep ":8080" | grep LISTEN)
And then I could get the expected response back using check_nrpe
remotely. So I assume this is some sort of problem with check_nrpe
and lsof
. But I could never find anything in the logs.
Anyone have any ideas or suggestions to get this to work right with lsof
?