- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我通过ssh登录了一个虚拟机,并尝试在后台运行一个脚本,脚本如下所示:
#!/bin/bash
APP_NAME=`basename $0`
CFG_FILE=$1
. $CFG_FILE #just some variables
CMD=$2
PID_FILE="$PIDS_DIR/$APP_NAME.pid"
CUR_LOG_DIR=$LOGS_RUNNING
echo $$ > $PID_FILE
#Main script code
#This script shall be called using the following syntax
# $ nohup script_name output_dir &
TIMESTAMP=`date +"%Y%m%d%H%M%S"`
CAP_INTERFACE="eth0"
/usr/sbin/tcpdump -nei $CAP_INTERFACE -s 65535 -w file_result
rm $PID_FILE
结果应该是 tcpdump 在后台运行,将命令结果重定向到 file_result。
脚本被调用:
nohup $SCRIPT_NAME $CFG_FILE start &
并且停止调用 STOP_SCRIPT:
##STOP_SCRIPT
PID_FILE="$PIDS_DIR/$APP_NAME.pid"
if [ -f $PID_FILE ]
then
PID=`cat $PID_FILE`
# send SIGTERM to kill all children of $PID
pkill -TERM -P $PID
fi
当我检查file_result时,运行停止脚本后,它是空的。
发生了什么?我该如何解决?
我找到了这个链接:https://it.toolbox.com/question/launching-tcpdump-processes-in-background-using-ssh-060614
作者似乎也遇到过类似的问题。他们争论比赛条件,但我没有完全理解。
最佳答案
我不确定通过让启动脚本本身继续运行来完成什么,但我认为这里有一种方法可以完成你想要做的事情,即 start tcpdump
并让它通过 nohup
继续运行不受挂断的影响.出于说明的目的,我已经稍微简化了一些事情 - 您可以随意添加任何您认为合适的变量,例如 nohup.out
输出目录、TIMESTAMP
等。
脚本 #1:tcpdump_start.sh
#!/bin/shrm -f nohup.outnohup /usr/sbin/tcpdump -ni eth0 -s 65535 -w file_result.pcap &# Write tcpdump's PID to a fileecho $! > /var/run/tcpdump.pid
脚本 #2:tcpdump_stop.sh
#!/bin/shif [ -f /var/run/tcpdump.pid ]then kill `cat /var/run/tcpdump.pid` echo tcpdump `cat /var/run/tcpdump.pid` killed. rm -f /var/run/tcpdump.pidelse echo tcpdump not running.fi
要启动 tcpdump,只需运行 tcpdump_start.sh
。
要停止以 tcpdump_start.sh
启动的 tcpdump 实例,只需运行 tcpdump_stop.sh
。
捕获的数据包将被写入 file_result.pcap 文件,是的,它是一个 pcap 文件,而不是文本文件,因此使用正确的文件扩展名命名它会有所帮助。 tcpdump 统计信息将在 tcpdump 终止时写入 nohup.out 文件。
关于linux - 为什么 tcpdump 不在后台运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61019058/
如何告诉tcpdump解析名称并保留未解析的端口号? 来自人: -n Don’t convert host addresses to names. This can be used to a
我正在使用 tcpdump 通过 wlan0 收集数据包数据。但是我发现很多数据包的长度为 0,如下图所示。嗯,长度为 0 的数据包...... tcpdump 可靠还是我错过了什么? 最佳答案 好的
运行“tcpdump -w 1.pcap”时需要限制文件大小。我尝试使用键“-C”来执行此操作,但是当我添加它时,我收到错误“权限被拒绝”。所以: > sudo tcpdump -w 1.pcap t
我正在通过网络适配器捕获 tcp/udp 数据包,并尝试分析数据包以获得一些统计指标,例如带宽速率或协议(protocol)效率。无论如何,我需要使用一些 CLI 工具来监视特定链路(源、目标、端口,
使用 tcpdump 在接口(interface)上捕获 LLDP 数据包的格式是什么? 我尝试了以下格式,但它不起作用: tcpdump -w test.pcap -i eth0 lldp -vv
我想使用 tcpdump 捕获网络流量,如果捕获的数据包增加为 10mb,我想创建另一个文件。我如何使用 tcpdump 安排此操作。请善意地帮助我。谢谢。 最佳答案 tcpdump -W 5 -C
使用 tcpdump 时,我似乎无法看到捕获的所有数据。具体来说,我似乎从帧头丢失了 6 个字节,我想知道是否有人可以解释原因。 为了说明这一点,我在 VMWare 上以仅主机网络配置设置了一个 Ub
我在使用 Android 应用程序中的 TCPDump 时遇到问题。它应该逐行读取 tcpdump 的输出并在我的应用程序中处理它。 问题是: 有时代码工作正常,它会立即读取捕获的数据包。但有时,Re
我都使用过,我的结论是我可以使用 tcpflow 从网页中读取 html 数据,但不能使用 tcpdump 这样做。我得到的最好的结果是一些丑陋的 ASCII 文本,其中有很多句点符号。 我的理解是
我需要在我的 Android 设备上执行 tcpdump 跟踪。 我的设置: 将tcpdump文件推送到sdcard adb push filepath/tcpdump /sdcard/tcpdump
我的电脑上有两个网络接口(interface)。 netstat -i Kernel Interface table Iface MTU Met RX-OK RX-ERR RX-DRP RX-
Linux中是否有诸如tcpdump之类的实用程序来捕获通过RDMA channel 传输的流量? (Infiniband/RoCE/iWARP) 最佳答案 旧线程,但仍然: 正如Roland指出的那
我有一个巨大的pcap文件(100GB),我对一小部分数据包感兴趣,我知道这些数据包的数量为5,000,000至5,000,020。 如何使用tcpdump读取pcap文件,按数据包编号(或范围)过滤
如何使用 tcpdump 捕获以太网帧并显示本地 PC 使用 UDP、ARP 和 ICMP 协议(protocol)之一发送或接收的任何帧。 我正在尝试这个命令: sudo tcpdump -e ud
我正在使用 tcpdump 捕获网络数据包,当我开始丢弃数据包时遇到问题。我运行了一个通过网络快速交换数据包的应用程序;导致网络带宽较高。 >> tcpdump -i eno1 -s 64 -B 91
是否可以指定tcpdump 测量接收和发送数据包的时间?我知道命令 tcpdump -c 100 指定 tcpdump 在收到 10 个数据包后应该停止。我想指定 tcpdump 在例如 5 分钟后停
运行以下命令时出现错误: sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/tcpdump* 这提供了以下错误: Failed to set cap
我可以为dst指定1个以上的tcpdump IP地址吗? 如果没有,如果我只想要两个特定目的地的流量,该如何很好地过滤信息? 非常感谢你! 最佳答案 是的,您可能有一个过滤器,其中包含多个通过“或”连
我正在寻找在 openwrt 上运行的 tcpdump 二进制文件。该网站仅显示必须构建的源代码。有人指向我包含预构建二进制文件的位置吗?谢谢。 最佳答案 我建议建立一个工作存储库,即: https:
在服务器 # nc -lp 2424 hi server hi client 1 2 3 在客户端 ➜ ~ nc 139.224.xxx.xx 2424 hi server hi client 1
我是一名优秀的程序员,十分优秀!