Запуск команд над несколькими файлами и именование новых файлов - PullRequest
0 голосов
/ 23 октября 2019

Вот сценарий bash. У меня есть 5 файлов PCAP. Я хочу выполнить эти команды для них, а затем дать имя новым файлам flow1 flow2 flow3 flow4 flow5 после каждого проходящего через него файла PCAP. Я не могу заставить его правильно называть файлы

новый файл выглядит как 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 Ответ

1 голос
/ 23 октября 2019

Не зная точно, что делают команды argus и ra, я подозреваю, что это ближе к тому, что вам нужно:

#!/bin/bash

count=0
for file in *.pcap; do
  ((count++))
  argus -r ${file} -w packet.argus
  ra -r packet.argus -s bytes dur -u > flow${count}.csv
  ra -r packet.argus -n -s bytes dur rate runtime pkts load loss > features.csv
  ra -r packet.argus -n -s stime ltime sport dport - dst port 53 > dns${count}.csv 
  ra -r packet.argus -n -s stime ltime sport dport - dst port 123 > ntp${count}.csv
  rm packet.argus 
done
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...