每次,当我手动运行tcpdump时,都必须使用 Ctrl + C 停止它.现在,我想用cronjob安排我的tcpdump,我只需要它运行1个半小时.如果不手动运行 Ctrl + C 或kill命令,如何自动将其停止?这是我正在测试的命令:
Each time, when I manually run tcpdump, I have to use Ctrl+C to stop it. Now I want to schedule my tcpdump with cronjob and I only need it to run for 1 and half hours. Without manually running Ctrl+C or kill command, how can it be stopped automatically? Here is the command I am testing:
tcpdump -i eth0 'port 8080' -w myfile我可以安排另一个cronjob杀死tcpdump进程,但这似乎不是一个好主意.
I can schedule another cronjob to kill the tcpdump process, but it seems not a good idea.
推荐答案您可以结合使用-G {sec}(每x秒旋转转储文件)和-W {count}(限制转储文件的数量)来获得所需的内容:
You can combine -G {sec} (rotate dump files every x seconds) and -W {count} (limit # of dump files) to get what you want:
tcpdump -G 15 -W 1 -w myfile -i eth0 'port 8080'将运行15秒,然后停止.将1.5小时变成几秒钟,它应该可以工作.
would run for 15 seconds and then stop. Turn 1.5 hours into seconds and it should work.
更多推荐
如何安排tcpdump在特定时间段内运行?
发布评论