Hi guys, I have the following script
#!/bin/bash
NRCORES=`mpstat | grep CPU | head -n1 | awk '{print $6}' | tr -d "(" | bc`
PIDOFJAVA=`pidof java`
`top -bn2 -p $PIDOFJAVA > "/usr/local/nagios/libexec/TopOutput.txt"`
OUTPUT=`cat "/usr/local/nagios/libexec/TopOutput.txt" | awk '{print $3}' | grep "," | tr -d "total," | tr -d "\r" | (read;cat)`
NRCORES=`echo $NRCORES| bc`
ENDLOOP=`echo $(($NRCORES*2)) | bc`
NRCORES=$(($NRCORES+1))
CORES=`echo $OUTPUT | awk '{
for (i='$NRCORES';i<='$ENDLOOP';i++)
print $i
}'`
CORES=`echo $CORES | tr "\s" "\;" | tr -d "\u" | tr -d " " | tr -d "%"`
CORES="SERVICE OK | spread=$CORES"
echo $CORES
#echo "SERVICE OK | spread=0.0;0.2;0.3;0.4;0.0;0.0;0.6;0.0;"
exit 0
If I run the script as THE NAGIOS USER, but without using nrpe, i get the following output:
[nagios@ws230 libexec]$./cpu_utilization.sh
spread=0.0;0.0;0.0;0.0;0.3;0.0;0.3;0.0;
[nagios@ws230 libexec]$
However, if i run the same script, but with NRPE, like this, I get a totally different.
[nagios@ws230 libexec]$./check_nrpe -H localhost -c command
spread=
[nagios@ws230 libexec]$
This FRUSTRATES ME, as if I echo $OUTPUT with nrpe in the script,
I get, usingNRPE
Without using NRPE:
I just don’t know what to do since the both the script and the TopOutput are owned by the nagios user/group and have write, read privileges.
So, for some reason, when I use nrpe, the TopOutput file cannot be fully read and only 2 lines are got. This is strange, since the NRPE deamon uses the same user as I am logged with locally in bash and executes the same command.
You will notice that I am even using absolute paths, so nothing can go wrong. In addition, even if I run the script in nrpe, it WRITES FULLY TO THE TopOutput file, but, however, cannot fully read it. Any hints?
Help!