2014-04-06 139 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[@]}"