Bash脚本upd错误

时间:2014-10-20 08:34:08

标签: bash

我执行我的bash脚本PLCCheck作为进程

./PLCCheck &

PLCCheck

while read -r line 
do 
    ... 
    def_host=192.168.100.110
    def_port=6002
    HOST=${2:-$def_host}
    PORT=${3:-$def_port}

    echo -n "OKConnection" | netcat -u -c $HOST $PORT 
done < <(netcat -u -l -p 6001)

它侦听UDP端口6001。

当我想执行我的第二个bash脚本SQLCheck作为侦听UDP端口4001的进程时

./SQLCheck &

SQLCheck

while read -r line 
do 
   ... 
   def_host=192.168.100.110 
   def_port=6002
   HOST=${2:-$def_host}
   PORT=${3:-$def_port} 

   echo -n "OPENEF1" | netcat -u -c $HOST $PORT 
done < <(nc -l -p 4001)

我收到了这个错误:

Error: Couldn't setup listening socket (err=-3)

端口6001和4001在iptables中打开,两个脚本都作为一个进程运行。为什么我会收到此错误?

1 个答案:

答案 0 :(得分:0)

我查看了nc的手册页。我认为这是以错误的方式使用:

 -l      Used to specify that nc should listen for an incoming connection rather
         than initiate a connection to a remote host.  It is an error to use this
         option in conjunction with the -p, -s, or -z options.  Additionally,
         any timeouts specified with the -w option are ignored.

...

 -p source_port
         Specifies the source port nc should use, subject to privilege restrictions
         and availability.  It is an error to use this option in conjunction with the
         -l option.

根据此情况,不应将-l选项与-p选项一起使用!

尝试不使用-p,只使用nc -l 4001。也许这就是错误...