使用awk

时间:2016-02-03 19:25:25

标签: bash shell awk

我是脚本新手。所以不要介意这个问题听起来很傻。 我试图运行一个脚本,它将使用net cat检查远程主机的特定端口。下面是运行的代码及其抛出错误, + result =' nc -vuz 192.168.199.211 1812 | awk' \'' {print}' \''' /tmp/check_udp_port.sh:第43行:意外令牌else' /tmp/check_udp_port.sh: line 43:附近的语法错误'

我不确定如何调试。如果你能得到一些有用的指导

#!/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}

0 个答案:

没有答案