PLINK does not return value inside plugin shell script


#1

Hi there,

I’ve written a shell script to use as a plugin. Inside the script, I run “plink” to a device to retrieve it’s temperatures. When running the script manually from the command like it works. When nagios executes it, I do not get any values returned from plink

(plink is a command line interface from putty)

Now I know the script runs because I see the “plink” process appear in “top” AND a tcpdump shows that ssh packets are sent/received but my script still doesn’t return any values.

I’m running Nagios Version 3.0rc1 on a Fedora Core 8 box.

Here’s a copy of my script:
#! /bin/sh

Script check_ls_temp.sh

Check the various temperature values of a LifeSize unit

help() {

echo "Usage: check_ls_temp.sh "
echo “Example: ./check_ls_temp.sh 142.92.141.104”
}

plink="/usr/local/bin/plink"
head="/usr/bin/head"

thehost=$1

if -z “$thehost” ]
then
echo "No IP Address"
help
exit 3
fi

thetemps=$plink -2 -l user -pw password $thehost get system temp | $head -n 1

here the variable the temp should contain 4 comma seperated values

#thetemps=“53,73,63,73”

if -z “$thetemps” ]
then
echo "No values retrieved from $thehost"
exit 3

This is where nagios gets to and spews out the results because thetemps is empty

fi

board=echo "$thetemps" | awk -F, '{print $1}'
video_in=echo "$thetemps" | awk -F, '{print $2}'
video_out=echo "$thetemps" | awk -F, '{print $3}'
ambient=echo "$thetemps" | awk -F, '{print $4}'

if $board -gt 84 ] || $video_in -gt 84 ] || $video_out -gt 84 ] || $ambient -gt 84 ]
then
echo -n "CRITICAL : Board:$board Video-in:$video_in Video-out:$video_out Ambient:$ambient"
exit 2
elif $board -gt 82 ] || $video_in -gt 82 ] || $video_out -gt 82 ] || $ambient -gt 82 ]
then
echo -n "WARNING : Board:$board Video-in:$video_in Video-out:$video_out Ambient:$ambient"
exit 1
else
echo -n "OKAY: Board:$board Video-in:$video_in Video-out:$video_out Ambient:$ambient"
exit 0
fi

echo -n "Unknown values or other problem"
exit 3

Here’s my command and service definitions:
define command{
command_name check_ls_temp
command_line $USER1$/check_ls_temp.sh $HOSTADDRESS$
}

define service{
use generic-service
host_name clinic_lifesize
service_description TEMPERATURES
check_command check_ls_temp
}

Please help.
thanks
Guy


#2

Okay I’ve figured it out.
I redirected stderr to a file and noticed that plink was prompting for a y/n to store the key file. I had done this manually by logging on as the nagios user but I guess it did not work.

What I did was generete a key pair using ssh-keygen and copied the .pub key to the device and now I use ssh instead of plink.

Thanks anyways …