2014-10-20 133 views
0

我执行我的bash脚本PLCCheck的过程bash脚本UPD错误

./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的开放,这两个脚本的工作作为一个单一的过程。为什么我会得到这个错误?

+0

嗯......两者都使用默认端口6002,但我看不到“PCLCheck”脚本中使用了“PORT”。也许他们碰撞... – TrueY 2014-10-20 08:50:56

+0

对不起。 'netcat -u -c $ HOST $ PORT'也是一样。 PLCCheck每5分钟发送一次。 SQLCheck每120-300分钟随机发送一次。 – Philipp88 2014-10-20 08:58:32

+1

尝试在两个脚本的开始处使用'set -x',并将它们作为前台进程在两个终端中启动,以查找出现此错误消息的行。根据你的部分脚本,它可以在任何行... – TrueY 2014-10-20 09:09:26

回答

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。也许这是错误...

+0

没有。不起作用。没有-p它不听信端口4001. – Philipp88 2014-10-20 08:55:28

+0

@ Philipp88:需要'-l',不需要'-p'。 – TrueY 2014-10-20 08:59:03

+0

没有-p,它不起作用。 – Philipp88 2014-10-20 09:09:30