Stuck with Nagios


#1

Hi all

I’ve got a major issue with Nagios. I’m a newb to Nagios.

I made some scripts that i need to run with Nagios (the scripts are shells).
So in my scripts I need to copy another script to my remote server, then i need to execute it and then the copied file needs to give back feedback so i can handle that information locally (it can sound crazy, but it doesn’t matter what they do, i just need to get this work).

So, if i run it in Nagios (testing it) i get some feedback (like echoes) but in my other script i also use echoes but Nagios doesn’t show it.

Oke, time for some code…
This is the mainscript:

#!/bin/bash

PATH="/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
"
# Exit codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3

# Initiliaze variables
EXITSTATUS=$STATE_UNKNOWN
echo testing

EXITSTATUS=$STATE_WARNING #default
while test -n "$1"; do
	case "$1" in
		--help)
			print_help
			exit $STATE_OK
			;;
		-h)
			print_help
			exit $STATE_OK
			;;
		--version)
			print_revision $PROGNAME $VERSION
			exit $STATE_OK
			;;
		-V)
			print_revision $PROGNAME $VERSION
			exit $STATE_OK
			;;
		--hostname)
			host=$2
			shift
			;;
		-H)
			host=$2
			shift
			;;
		-p)
			path=$2
			shift
			;;
		--path)
			path=$2
			shift
			;;
		*)
			echo "Unknown argumen: $1"
			print_usge
			exit $STATE_UNKNOWN
			;;
	esac
	shift
done

# Copying a file to the remote server
# Then executing the script I just copied
scp $path user@$host:/some/folder
ssh user@host 'echo hello'
VAR=$(ssh user@$host './scp_cd.sh')
echo $VAR
#ssh user@host 'rm -f /home/vusbe/scp_cd.sh'

if  $VAR = 2 ]; then
		EXITSTATUS=$STATE_CRITICAL
		echo STATE_ERROR
		
	elif  $VAR = 1 ]; then
		EXITSTATUS=$STATE_WARNING
		echo STATE_WARNING
else
	echo niks aan de hand
	EXITSTATUS=$STATE_OK
fi

# End of script
echo script is ten einde

and this is the subscript:

#!/usr/bin/ksh
echo subscript

error=`ls /some/folder/ | grep error* | wc -w`
warning=`ls /some/folder/ | grep -ie *.tmp | wc -w`

if  $error -gt 0 ]; then
	i="0" # ERROR MESSAGE
else
	i="0" # OK MESSAGE
fi

echo $i

this is what i use in Nagios
$USER1$/check_test.sh -H remote_server -p path_to_script_needed_to_copy

I have also did a SSH-KEYSWAP so i don’t need to log me in everytime, and this works

can someone help me?