I am using tcpflow to log network traffic on a server. I want to log this data to a file, but not all of it. The monitoring process would be running in the background as a daemon indefinitely.
Some lines of the stream include a byte count, and if I see that byte count (say, 800 bytes), then I need to log the next 800 bytes to the file. If not, I wish to not write to the file.
What's the best way for me to do this kind of "on-the-fly pre-processing" of the stream to decide what to redirect to the log file? Some kind of second daemon script that is listening to the stream, which gets piped in to that script?
Example:
I see the following line in the stream:
1343932842: 010.079.091.189.35856-010.104.001.199.11211: set i:1:20163484235 0 0 1429
First, I need to check that it has a "set". Then, I examine the last piece of the line (1429), then read the next 1429 bytes and write those to a file.