如何安排tcpdump在特定时间段内运行? [英] How to schedule tcpdump to run for a specific period of time?

查看:709
本文介绍了如何安排tcpdump在特定时间段内运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

每次,当我手动运行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在特定时间段内运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆