2014-04-06 96 views
0

我试图执行tshark的命令来查找在bash命令特定IP地址的数据包,而正在执行脚本的错误如下如下::如何从bash脚本执行tshark的命令

while read client 
do 
echo "Client Adrees:" $client1 
cmd="tshark -R \"(ip.src == 10.129.5.192)\" -r 12clients.pcap" 
echo $cmd 

done < input 

: :

Client Adrees: 10.129.26.154 
tshark -R "(ip.src == 10.129.5.192)" -r 12clients.pcap 
tshark: Read filters were specified both with "-R" and with additional command-line arguments 

在此先感谢...:d

+0

http://mywiki.wooledge.org/BashFAQ/050 – tripleee

回答

2

使用的阵列变量,而不是存储和执行你的命令 - USI ng带有文字双引号的单个字符串将不会被正确解释:

# Store command tokens in an array. 
# Note that each word or quoted phrase will form a separate array element. 
cmd=(tshark -R "(ip.src == 10.129.5.192)" -r 12clients.pcap) 

# Invoke command as the expanded array. 
# Double-quoting it prevents shell expansions of the elements. 
"${cmd[@]}"