将grepped的尾巴输出发送到netcat [英] Send grepped tail output to netcat
问题描述
我正在尝试运行以下命令,并且没有任何内容发送到netcat
I am trying to run the following command, and nothing is getting sent to netcat
tail -F file.txt | grep test | nc host 9999
如果我删除grep,则会成功跟踪尾部并将其发送到netcat.
If I remove the grep, the tail successfully is followed and sent to netcat.
如果我只运行以下命令,数据将返回,因此我知道应该将数据发送到nc管道:
If I just run the following, data comes back, so I know that data should be getting sent to the nc pipe:
tail -F file.txt | grep test
有什么想法吗?
更新
我添加了以下内容来取消缓冲管道输出,但没有任何结果:
I added the following to unbuffer the piped output and nothing goes through:
tail -F file.txt | stdbuf -o0 grep test | nc host 9999
当我打开行缓冲时,输出会被切断
When I turn on line buffering, output is cut off
tail -F file.txt | grep --line-buffered test | nc host 9999
哪里
workid: ID:ITEST_HGR1-EMS12103.1A156BB6CEB1:10F76E5D
发送为
workid: ID:ITEST_HGR1-EMS12103.1A156BB6CEB1:10F7
推荐答案
您需要更改 grep
的默认缓冲行为.如果您使用的是GNU grep,则可以使用 grep --line-buffered
,或尝试使用 unbuffer
.
You need to change the default buffering behavior of grep
. If you're on a GNU grep, you can use grep --line-buffered
, or try unbuffer
.
这篇关于将grepped的尾巴输出发送到netcat的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!