Script is at Server:
#!/bin/bash
if [ ! $# == 1 ]; then
echo "Usage check_cluster "
fi;
clu_srv=$1
error="stopped"
error1="disabled"
error2="recoverable"
host1=`sudo /usr/sbin/clustat|grep $1| awk {'print $2'}`
host2=`sudo /usr/sbin/clustat|grep $1| awk {'print $3'}`
service1=`sudo /usr/sbin/clustat|grep $clu_srv| awk {'print $1'}`
if [[ "$host2" == "$error" ]] || [[ "$host2" == "$error1" ]]; then
echo "CRITICAL - Cluster $clu_srv service failover on $host1 and state is '$host2'"
else
echo "OK - Cluster $clu_srv service is on $host1 and state is '$host2'"
fi;
##--EndScript
It receives thee argument from script correctly. When I running this script manually at Server from command line it returns correct information, for example:
# /usr/local/nagios/libexec/check_rhcs-ERS NFSService OK - Cluster NFSService service is on NODE1 and state is 'started'
But when I tried with the script (check_nrpe) remotely with following command its showing incorrect information:
# ./check_nrpe -H localhost -c check_rhcs-ERS OK - Cluster NFSService service is on and state is ''
nrpe.cfg:
# command[check_rhcs-ERS]=/usr/local/nagios/libexec/check_rhcs-ERS NFSService
What is Wrong with the script, How to fix it?
-xto the first line (#!/bin/bash -x) and immediately after that add a new line after that to capture the stderr+stdout output to a logfile (exec > /tmp/nrpetest.$$.log 2>&1) then call the script via NRPE again. Review the log file that is generated to see where the script is failing. – Gene Aug 16 '16 at 07:55ifstatement should include appropriateexitcommands to return the desired return code. https://nagios-plugins.org/doc/guidelines.html#AEN78 – Gene Aug 16 '16 at 08:17