简体   繁体   English

在bash中运行多个命令并创建新目录并将CSV文件移动到新目录中

[英]Running multiple commands in bash and creating new directories and moving csv files into the new directory

I have several pcap files on which I would like to apply the same commands on (these are Argus commands a network flow tool) 我有几个要在其上应用相同命令的pcap文件(这些是网络流量工具Argus命令)

  • Convert the PCAP file to an argus file 将PCAP文件转换为argus文件
  • Run four Argus commands that outputs 4 .csv files 运行四个输出4个.csv文件的Argus命令
  • Create a new directory based on the .pcap file name but with only the first part of the pcap name eg amazonecho_merge I didnt want the merge part as part of the new directory name 基于.pcap文件名创建一个新目录,但仅包含pcap名称的第一部分,例如amazonecho_merge我不希望将合并部分作为新目录名称的一部分
  • Place all new .csv files into the new directory 将所有新的.csv文件放入新目录

      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 #Run argus to get the source and destination ports, merge both columns together and count how many occurances racluster -r packet.argus -n -s sport dport > ports.csv ra -r packet.argus -s stime ltime sport dport - dst port 53 > DNS.csv ra -r packet.argus -s stime ltime sport dport - dst port 123 > NTP.csv dir=$(echo ${file} | awk -F. '{print $1}' OFS=.) mkdir $dir #Move all newly created .csv files to the new directory mv $file*.csv $dir done 

I think naming the new directory is incorrect as I only want part of the name of the pcap file 我认为命名新目录是不正确的,因为我只想要部分pcap文件的名称

I am sure there is a better way of running the commands especially this one 我敢肯定,有一种更好的方式来运行命令,尤其是这一种

  ra -r packet.argus -s stime ltime sport dport - dst port 53 >   DNS.csv 
  ra -r packet.argus -s stime ltime sport dport - dst port 123 >   NTP.csv

when there is only slight change in the command I would like to know if there is a easier format of running these commands 当命令中的更改很小时,我想知道是否有一种更简单的格式来运行这些命令

Is there a way in bash to merge the columns from the different csv files into single csv file bash中是否有一种方法可以将来自不同csv文件的列合并为单个csv文件

e.g 

      file1.csv

      A,B

      file2.csv

      C,D

      Desired output.csv

      A,B,C,D

I have tried join and does not work is there any other bash command that will work? 我试过加入但不起作用,是否还有其他bash命令会起作用?

It looks like most of your commands don't need to run once per file, so if you change the order you can save some runtime: 看来大多数命令不需要每个文件运行一次,因此,如果更改顺序可以节省一些运行时间:

#!/usr/bin/env bash

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

# Run argus to get the source and destination ports, merge both columns together and count how many occurances
racluster -r packet.argus -n -s sport dport > ports.csv
ra -r packet.argus -s stime ltime sport dport - dst port 53 > DNS.csv
ra -r packet.argus -s stime ltime sport dport - dst port 123 > NTP.csv

for file in *.pcap
    do
    dir=$(echo $file| awk -F_ '{print $1}')
    mkdir $dir
    # Move all newly created .csv files to the new directory 
    mv $file*.csv $dir
done

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 BASH 创建多个目录,移动文件,然后重命名所述文件的脚本 - BASH Script for creating multiple directories, moving files, and then renaming said files Bash:将同级目录中名称相同的文件移动到新目录结构 - Bash: move identically named files in sibling directories to new directory structure Bash监视目录并将文件移到新位置 - Bash Monitoring directory and moving files out to a new location 更改文件的新内容并移动到Bash中的新目录 - changing a new of a file a moving to a new directory in Bash 进入多个目录,查找具有特定扩展名的文件并复制到新目录 - Enter to multiple directories, find files with specific extension and copy to a new directory 运行bash脚本以创建新目录时出错 - Error when running bash script for creating a new directory 在多个文件上运行命令并命名新文件 - Running commands over multiple files and naming of new files 如何在 bash 中将文件复制到同一目录中但跨多个目录的具有新名称的新文件? - How to copy a file to a new file with a new name in same directory but across multiple directories in bash? bash:使用文件名列表跨目录连接匹配文件并将所有文件保存在新目录中 - bash: use list of file names to concatenate matching files across directories and save all files in new directory Bash脚本,用于搜索目录并将文件移动到新目录,删除所有副本 - Bash script for searching directory and moving files to a new directory, deleting any copies
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM