I need to run tshark to record packets for a long time. While saving the packets I wand to also apply display filters as they are parsed to detect errors.
Not to fill the disk and create huge files I want to use it with --ring-buffer option The problem is that tshark doesn't support to apply display-filters and to save to file in the same time.
I could use tee to pipe with tshark or tcpdump, but this doesn't work with the ring buffer files. Or to use 2 separate processes for this, but it is still the problem with the output files being created and deleted.
Is is possible to have this only with tshark? or should I just search for other tool like tee that generates the circular buffers?
thanks
Perhaps using a combination of
tcpdumpandtsharkwould be useful to you, as in this example?Contents of
tshark.shexecutable script:After each file has reached its size limit, the
-z postrotatecommand will be called, andtsharkwill be able to post-process the file. This isn't real-time per se, as there will be a delay beforetsharkruns, and it will do so on all packets in the file at once, so you'll get batches of output at a time. You can control the delay to some degree by experimenting with values passed to-C. Larger values will create bigger files but will also incur larger delays intsharkpost-processing.Ideally you could also specify
tcpdump's-G rotate_secondsoption, but the man page currently indicates that, "If used in conjunction with both -C and -G, the -W option will currently be ignored, and will only affect the file name." I'm not sure why that's the case, but you might consider filing atcpdumpenhancement bug request to see if someone is willing to change this behavior.You should also be aware of Issue #1015: postrotate-command not run when tcpdump terminated.