grep with continuous pipe does not work

前端 未结 2 952
我寻月下人不归
我寻月下人不归 2021-01-19 07:55

(maybe it is the \"tcpflow\" problem)

I write a script to monitoring http traffic, and I install tcpflow, then grep

it works (a

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-19 08:39

    I think the problem is because of stdio buffering, you need to use GNU stdbuf before calling grep,

    sudo tcpflow -p -c -i eth0 port 80 2>/dev/null | stdbuf -o0 grep '^Host: '
    

    With the -o0, it basically means the output (stdout) stream from tcpflow will be unbuffered. The default behavior will be to automatically buffer up data into 40961 byte chunks before sending to next command in pipeline, which is what overriden using stdbuf


    1. Refer this nice detail into the subject.

提交回复
热议问题