2012-11-27 134 views
1

我正在寻找一个bash脚本的想法,该脚本运行tethereal -w /path/to/file1.pcap一段有限或指定的时间量,然后结束并重新启动具有稍微不同输出的cmd文件名,所以它写的第二个文件是类似file2.pcapBASH脚本运行tethereal

我正在思考某种循环的行,但我不知道如何做到这一点,因为我的脚本经验是有限的。

所有帮助感激地接受 非常感谢

farmorg

回答

0
timeout_const=10 
for i in {1..5} 
do 
    timeout $timeout_const tethereal -w /path/to/file${i}.pcap 
done 
+1

你也可以用'因为我{1..5}'。 –

+0

这是行不通的,因为只要你运行第一个tethereal命令,你就不会退出它。 – pabrantes

+0

超时会否杀死它? –

0
timeout=10 
for i in `seq 1 N` # notice that N we'll be your upper bound 
do 
    tethereal -w /path/to/file${i}.pcap & 
    sleep $timeout; 
    PID=`ps aux | grep tethereal | awk '{print $1}'`; 
    kill -9 $PID; 
done 
+0

NAME 超时 - 运行有时间限制 概要 超时[选项] duration命令[ARG] ... 超时[选项] 描述 启动命令,并杀死它,如果时间后仍在运行的命令。 –

+0

是的鲍里斯,就像我在下面的回答中评论过的,你对超时是正确的。我的错。 – pabrantes