gpt4 book ai didi

linux - 在命令行命令列表中使用 tcpdump 时出错

转载 作者:太空宇宙 更新时间:2023-11-04 09:52:56 24 4
gpt4 key购买 nike

我尝试在后台运行 tcpdump,同时通过 eth0 发送一些流量,然后在发送流量后 pkill tcpdump 进程。

当我在后台单独运行 tcpdump 时,它运行没有错误:

bash~~$ sudo /usr/sbin/tcpdump -i eth0 -s0 -w /tmp/eth0.pcap &
[1] 19282
bash~~$ tcpdump: listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes

bash~~$

然后我可以 pkill 之后的 tcpdump:

bash~~$ ps -ef | grep tcpdump; sleep 1; sudo pkill tcpdump; ps -ef | grep tcpdump
fred 20437 15842 0 11:55 pts/2 00:00:00 grep tcpdump
fred 20467 15842 0 11:55 pts/2 00:00:00 grep tcpdump
bash~~$

现在,当我将以上所有内容放在一起时,我似乎无法通过最初的 tcpdump 调用:

bash~~$ sudo /usr/sbin/tcpdump -i eth0 -s0 -w /tmp/eth0.pcap & ; ps -ef | grep tcpdump; sleep 1; sudo pkill tcpdump; ps -ef | grep     tcpdump;
-bash: syntax error near unexpected token `;'
bash~~$

关于我遗漏的任何想法? tcpdump 的行为是否与其他函数不同?

一个

最佳答案

& 符号 &; 一起是管道终止符, &&|| .您不应同时指定两个不同的管道终止符,而应根据需要选择一个。在这里,你可能想要

sudo /usr/sbin/tcpdump -i eth0 -s0 -w /tmp/eth0.pcap & ps -ef | grep tcpdump; sleep 1; sudo pkill tcpdump; ps -ef | grep tcpdump;

相关摘录自bash manpage :

A pipeline is a sequence of one or more commands separated by one of the control operators | or |&.

A list is a sequence of one or more pipelines separated by one of the operators ;, &, &&, or ││, and optionally terminated by one of ;, &, or <newline>.

关于linux - 在命令行命令列表中使用 tcpdump 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9033085/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com