0

Im newbie to scripting. So dont mind if the question sound silly. Am trying to run a script which will check the specific port of remote host using net cat. Below is the code am running and its throwing error, + result='nc -vuz 192.168.199.211 1812 | awk '\''{print }'\''' /tmp/check_udp_port.sh: line 43: syntax error near unexpected token else' /tmp/check_udp_port.sh: line 43: else'

I am not sure how to debug. If you could get some guidance that will be helpful

#!/bin/sh
#
# check_udp_port - Checks if a UDP port is open using nmap utility
#
# Author:       Aaron Eidt (aeidt4@uwo.ca)
#

STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3
STATE_DEPENDENT=4


host=
port=

while getopts H:p:s: o
do
        case $o in
                H)
                        host="$OPTARG"
                        ;;
                p)
                        port="$OPTARG"
                        ;;
        esac
done

#if [ x$host = x -o x$port = x  ]; then
#       usage
#       exit ${STATE_UNKNOWN}
#fi

result="nc -vuz $host $port | awk '{print $7}'"



if [ "echo $result == 'suceeded'"]

                echo "OK: $service listening on port $port"
                exit ${STATE_OK}
        else
                echo "WARNING: Incorrect service $nmap_service listening on port $port: $p_result"
                exit ${STATE_WARNING}
        fi
fi

echo "CRITICAL: $p_result"
exit ${STATE_CRITICAL}
pradeep s
  • 9
  • 2

0 Answers0