Frage

i am trying to execute the tshark command to find packets of a particular IP address in bash command as follows::

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

done < input

while executing script the error is as follows::

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

thanks in advance... :D

War es hilfreich?

Lösung

Use an array variable instead to store and execute your command - using a single string with literal double quotes won't be interpreted correctly:

# 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[@]}"
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top