`

管道的一个应用: 将一个tcp端口的输出转移到另外一个tcp端口而输出

阅读更多

  案例: 有一个应用程序需要把数据输出给远程tcp端口44441, 为了安全, 数据会再次转发到端口44442,从而使得连接到端口44442的应用可以实时接收到数据。

   为此,在远程tcp主机编写了shell脚本如下:

#!/bin/bash -l

pipe=/tmp/testpipe

ps -ef | grep -e '44441' -e '44442' | grep -v 'grep' | awk '{print $2;}' | xargs kill -9 > /dev/null 2>&1
trap "rm -f $pipe" EXIT

if [[ ! -p $pipe ]]; then
    mkfifo $pipe
fi

ncat -lk -p 44441 0<"$pipe" | ncat -lk -p 44442 | tee $pipe &

 

0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics