Send grepped tail output to netcat

我怕爱的太早我们不能终老 提交于 2021-01-28 14:27:08

问题


I am trying to run the following command, and nothing is getting sent to netcat

tail -F file.txt | grep test | nc host 9999

If I remove the grep, the tail successfully is followed and sent to netcat.

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

Any ideas?

UPDATE

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

Where

workid: ID:ITEST_HGR1-EMS12103.1A156BB6CEB1:10F76E5D

is sent as

workid: ID:ITEST_HGR1-EMS12103.1A156BB6CEB1:10F7 

回答1:


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.



来源:https://stackoverflow.com/questions/35930207/send-grepped-tail-output-to-netcat

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!