开发者

Pipe netstat output multiple times

I want to store current开发者_如何学C network traffic [b/s] in Mac OS X into a file once a second.

netstat -b -n 1 |awk '{print $3}' |tail -n +3 >traffic.txt

should do want I want to - but the second pipe seems to be buffered, and I need the results as soon as possible.

If I only use one pipe, everything's fine, but I need at most these three.

ulimit -p 0 doesn't work (not implemented?). Is there any other way to avoid buffering?


awk will buffer its output by default. Call fflush() to flush it.

netstat -b -n 1 |awk '{print $3;fflush()}' |tail -n +3 >traffic.txt


Pipes are buffers, and they will send along data when they get around to it. I don't know of a way to speed them along.

Also, did you mean >> traffic.txt at the end? Your solution would truncate, two angle brackets appends.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜