问题
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