循环的批处理文件转换为另一个shell脚本1

时间:2014-08-03 18:11:37

标签: shell batch-file converter

任何人都可以帮助将此批处理文件代码转换为Unix Shellscript。

For %%f in (f\\*) do (
tshark -r %%f -T fields -e frame.number -e frame.time -e ip.src -e tcp.srcport -e ip.dst -e tcp.dstport -e tcp.seq -e tcp.ack -e tcp.window_size -e tcp.flags -e http.request.method -e http.response.code -e frame.time_epoch -e ip.len -E header=y -E separator=, -E quote=d -E occurrence=f> out\\%%f.csv
 )
goto :eof

谢谢,

更新

-rw-rw-r-- 1 ravising ravising  44957 Aug 16 06:33 f\f.pcap.TCP_74-125-68-157_443_172-16-210-197_47020.pcap
-rw-rw-r-- 1 ravising ravising   6174 Aug 16 06:33 f\f.pcap.TCP_74-125-68-157_443_172-16-210-197_47022.pcap
-rw-rw-r-- 1 ravising ravising   6133 Aug 16 06:33 f\f.pcap.TCP_74-125-68-157_443_172-16-210-197_47065.pcap
-rw-rw-r-- 1 ravising ravising   6503 Aug 16 06:33 f\f.pcap.TCP_74-125-68-157_443_172-16-210-197_47070.pcap

这些在我的文件名列表之上..

如果我为这个运行这个shell脚本......它不能正常工作

for f in f/*; do
    tshark -r "$f" -T fields -e frame.number -e frame.time -e ip.src -e tcp.srcport -e ip.dst -e tcp.dstport -e tcp.seq -e tcp.ack -e tcp.window_size -e tcp.flags -e http.request.method -e http.response.code -e frame.time_epoch -e ip.len -E header=y -E separator=, -E quote=d -E occurrence=f > out/"$f".csv
done
exit

2 个答案:

答案 0 :(得分:1)

运行此脚本后请显示所有消息。

#!/bin/bash
shopt -s nullglob
mkdir -p out
for f in f/*; do
    echo "Processing file $f."
    tshark -r "$f" -T fields -e frame.number -e frame.time -e ip.src -e tcp.srcport -e ip.dst -e tcp.dstport -e tcp.seq -e tcp.ack -e tcp.window_size -e tcp.flags -e http.request.method -e http.response.code -e frame.time_epoch -e ip.len -E header=y -E separator=, -E quote=d -E occurrence=f > out/"${f##*/}".csv
done
exit

答案 1 :(得分:0)

for f in f\\*; do
tshark -2 -r "$f" -T fields -e frame.number -e frame.time -e ip.src -e tcp.srcport -e ip.dst -e tcp.dstport -e tcp.seq -e tcp.ack -e tcp.window_size -e tcp.flags -e http.request.method -e http.response.code -e frame.time_epoch -e ip.len -E header=y -E separator=, -E quote=d -E occurrence=f> out/"$f".csv
done
exit

如果你有以下文件,那么这对我有用

-rw-rw-r-- 1 ravising ravising  44957 Aug 16 06:33 f\f.pcap.TCP_74-125-68-157_443_172-16-210-197_47020.pcap
-rw-rw-r-- 1 ravising ravising   6174 Aug 16 06:33 f\f.pcap.TCP_74-125-68-157_443_172-16-210-197_47022.pcap
-rw-rw-r-- 1 ravising ravising   6133 Aug 16 06:33 f\f.pcap.TCP_74-125-68-157_443_172-16-210-197_47065.pcap
-rw-rw-r-- 1 ravising ravising   6503 Aug 16 06:33 f\f.pcap.TCP_74-125-68-157_443_172-16-210-197_47070.pcap