Check_nrpe unable to read output from script

If you have configured sudo correctly its probably a problem with Requiretty, you should tell sudo not to require for nrpe.

See sudoers: how to disable requiretty per user


Your NRPE user most likely doesn't have permissions to run commands with sudo access.

To allow this, you can add the line below to your /etc/sudoers file using visudo. You can also omit the NFSService part if you don't want to restrict that part.

nrpe ALL=(ALL) NOPASSWD: /usr/sbin/clustat NFSService

That said, your script does need improving. It also only takes one parameter, not three - the $2 and $3 variables are awk arguments, not bash parameters.

My partially-edited version is below:

#!/bin/bash


if [ $# -ne 1 ]; then
  echo "Usage check_cluster " >&2
  exit 1
fi

clu_srv=$1

error="stopped"
error1="disabled"
error2="recoverable"

host1=$(sudo /usr/sbin/clustat | grep "${clu_srv}" | awk '{ print $2 }')
host2=$(sudo /usr/sbin/clustat | grep "${clu_srv}" | awk '{ print $3 }')
service1=$(sudo /usr/sbin/clustat | grep "${clu_srv}" | awk '{ print $1}')

The error-handling part of your script needs clarifying - what conditions do you want to catch? Your OK output gives the status for host2, but says that the service is on host1.