i created a Bash script that allows me to check for connection (ping or specific port) from a monitored Solaris 10 server to other destinations.
the script works on its own, but not when ran from NCPA. am I calling it wrong?
Code: Select all
#!/bin/bash
server=$1;
port=$2;
#netcat location
#netcat=nc
netcat=/opt/csw/bin/netcat
#timeout time. maximum time to wait before exiting with timeout
timeout=15
if [ $# -lt 2 ];then
echo "$0 <server> <port>"
echo "$0 nagios 80"
exit 1;
fi
s=$(nawk "BEGIN{print srand}")
check_port=$($netcat -v -z $server $port -w $timeout 2>&1; echo -n $?)
exit_code=${check_port: -1}
length=${#check_port}
result=${check_port:0: length - 1}
f=$(nawk "BEGIN{print srand}")
sum=$(( $f - $s ))
if [[ $exit_code == 0 ]]; then
echo "$result|time="$sum"s;;;0 "
exit $exit_code
else
echo "ERROR: netcat $server $port failed - critical|time="$sum"s;;;0 "
exit $exit_code
fi