"segmentation fault" with check_by_ssh

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
unixc
Posts: 1
Joined: Wed Dec 19, 2012 2:30 am

"segmentation fault" with check_by_ssh

Post by unixc »

I'm trying to configure a bash script to be run with nagios plugin - check_by_ssh. The is to check if a process (I've used syslogd here) is running or not after ssh'ing into the server with "check_by_ssh" plugin. If running/sleeping the script will return 0. Else if the process has T or Z state, the script will return 1, else the script exits with exit 2. The final aim is to display the status of process as as ok,warn or critical on the nagios web interface.

Code: Select all

    #!/bin/bash
    pid=`/sbin/pidof syslogd`

    if /sbin/pidof syslogd &> /dev/null; then
      while read name first rest; do
      if [[ $name = "State:" ]] ; then state="$first"; break;
      fi;
      done </proc/$pid/status;
  case "$state" in
            S|R|D)       #echo "Running fine"
                            exit 0
                            ;;
            T|Z)         #echo "Some problem"
                           exit 1
                           ;;
    esac
    else
    #echo "Process does not exist"
    exit 2;
    fi
But when I run this code as:

Code: Select all

/usr/lib/nagios/plugins/check_by_ssh -l www-data -H x.x.x.x -C 'bash /usr/local/scripts/check'
I get the below error:

Code: Select all

Segmentation fault
When i run the bash script locally on the destination server, I get returned the exact status code of the process being checked. But it fails when I run as mentioned above. If I uncomment the 'echo' lines in the script, I get returned "Running fine" as the result of above command. Is my approach correct here in this case?
slansing
Posts: 7698
Joined: Mon Apr 23, 2012 4:28 pm
Location: Travelling through time and space...

Re: "segmentation fault" with check_by_ssh

Post by slansing »

Try changing how you defined the command to be run on your Nagios system to this format:

Code: Select all

check_by_ssh -H <host> -C <command> [-fqv] [-1|-2] [-4|-6]
As opposed to placing -l before the Host's IP.
Locked