如何安排tcpdump在特定时间段内运行?

编程入门 行业动态 更新时间:2024-10-21 14:26:15
本文介绍了如何安排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在特定时间段内运行?

本文发布于:2023-06-11 03:50:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/626142.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:时间段内   在特定   tcpdump

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!