如何从bash脚本执行tshark命令

时间:2014-04-06 14:28:34

标签: bash shell sh wireshark

我正在尝试执行tshark命令以在bash命令中查找特定IP地址的数据包,如下所示::

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

1 个答案:

答案 0 :(得分:2)

使用数组变量来存储和执行命令 - 使用带有文字双引号的单个字符串不会被正确解释:

# 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[@]}"