我想使用cron(Raspberry Pi)中的Tcpdump捕获PCAP文件。我已经写了一个bash文件。但是,我想每天在一个新文件中捕获流量并停止旧的捕获。目前创建了一个新文件,但较旧的文件仍在捕获
#Variable
DATE=$(date '+%Y-%m-%d_%H%M%S')
SET_INTERFACE=eth0
SAVE_IN_FOLDER=/media/pi/tinausb
SAVE_AS_FILE=tcpdump_$DATE.pcap
#Execute tcpdump command
/usr/sbin/tcpdump -G 86400 -i $SET_INTERFACE -s0 -w
SAVE_IN_FOLDER/$SAVE_AS_FILE"
答案 0 :(得分:1)
-G rotate_seconds
If specified, rotates the dump file specified with the -w option
every rotate_seconds seconds. Savefiles will have the name
specified by -w which should include a time format as defined by
strftime(3). If no time format is specified, each new file will
overwrite the previous.
If used in conjunction with the -C option, filenames will take
the form of `file<count>'.
这意味着使用-w命名的文件名必须包含您至今传递的%格式。简而言之:
SAVE_AS_FILE=tcpdump_%Y-%m-%d_%H%M%S.pcap
哦,您的问题与Python btw无关。