【发布时间】:2019-10-23 23:03:27
【问题描述】:
这是一个 bash 脚本,我有 5 个 PCAP 文件我想对它们运行这些命令,然后在它通过的每个 PCAP 文件之后将新文件命名为 flow1 flow2 flow3 flow4 flow5 我无法正确命名文件
新文件显示为 1 个长字符串 flow1 flow2 flow3 flow4 flow5 仅用于 1 个文件
flow=(flow1 flow2 flow3 flow4 flow5)
dns=(dns1 dns2 dns3 dns4 dns5 dns6)
ntp=(ntp1 ntp2 ntp3 ntp4 ntp5 ntp6)
#creates a new directory based on the PCAP folder name
for file in *.pcap
do
argus -r *.pcap -w packet.argus &&
#Run argus to get the flow volumn (totalbytes) and the flow duration (seconds)
#ra -r packet.argus -s bytes dur > flow_vol_dur.csv
ra -r packet.argus -s bytes dur -u > "${flow[*]}.csv"
ra -r packet.argus -n -s bytes dur rate runtime pkts load loss > features.csv &&
#Run argus to get the source and destination ports, merge both columns together and count how many occurrences
#racluster -r packet.argus -n -s sport dport > ports.csv &&
ra -r packet.argus -n -s stime ltime sport dport - dst port 53 > "${dns[*]}.csv"
ra -r packet.argus -n -s stime ltime sport dport - dst port 123 > "${ntp[*]}.csv" &&
rm packet.argus
done
【问题讨论】:
-
有一些明显的问题:1)您的
for循环正在遍历当前目录中的所有*.pcap文件并将每个文件放在${file}变量中,但您不是在循环中的任何命令中使用该变量。 2) STDOUT 重定向运算符 (>) 采用单个文件名。您正在传递"${flow[*]}.csv",它是一个包含flow数组所有元素的字符串。这不是你想要的。
标签: bash