Hi guys, I have the following script
Code:
#!/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:
Code:
[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.
Code:
[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,
using NRPE
Without using NRPE:
Code:
0.6%us 1.2%us 1.2%us 1.2%us 0.8%us 0.6%us 0.7%us 0.6%us 0.0%us 0.0%us 0.0%us 0.3%us 0.0%us 0.0%us 0.0%us 0.0%us
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, the top executes differently when called by the same user but once from NRPE and once from the script residing locally. This is strange, since the NRPE deamon uses the same user as I am logged with locally in bash and executes the same script.
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, I can clearly see its output is totally different from the output it produces if called from the script itself. Any hints?
Help!
EDIT: I found what the problem is. TOP has different .toprc with different users. However, I am not sure how to edit the TOPRC for the nagios user so it is the same as the .toprc for the root user. They look the same to me. Is there a way to tell the top command which configuration file to use?
EDIT2:it seems to me this is a bug in the procps package. That is why I updated it to the latest version for my distroCentOS 5.5 and procps to the following
http://rpm.pbone.net/index.php3/stat...86_64.rpm.html
HOWEVER, it doesn't work even now and top, called from NRPE (with user nagios) uses its SHITTY defaults, while top, called normally (again, with user nagios) somehow FINDS /home/nagios/.toprc and uses it. I can't seem to grasp what its problem is. Is there something besides which user you are that can affect top's behavior?
I can't believe that nobody in this forum haven't seen the problem.