I have been stuck on this for way to long now. Tried googling and couldn't find what I was looking for.
I simply need to add all the values in an array.(array called packets) I have gotten to the point where I can add them, however when that happens the number value is not able to be called upon later in the script.
Here is the whole script, pretty simple just checking amount of packet data compared to time, aka bandwidth.
rawdata=`tcpdump -nn -S -r test.pcap | awk '{print $1" "$NF}'`
time="`echo "$rawdata" | sed -r 's/(.{15}).*/\1/'`"
starttime="`echo "$time" | awk 'NR > 1 { exit }; 1'`"
endtime="`echo "$time" | awk 'END{print}'`"
stime=`date --date="$starttime" +%s`
etime=`date --date="$endtime" +%s`
difftime="echo $(($etime - $stime))"
echo $difftime
echo $addedpackets
echo $sum
echo ------------------------------------
packets="`echo "$rawdata" | awk '{print $2}' | sed 's/[^0-9]*//g'`"
echo ------------------------------------
for i in "${packets[*]}"
do
plus=$(printf '%d+' ${i})0
added="echo $(($plus))"
done
echo ------------------------------------
$added
$difftime
bc -l <<< "$added/$difftime"
echo ------------------------------------
packets
you set on the line 12 is not an array. It is a simple scalar variable. – pabouk - Ukraine stay strong Jun 08 '15 at 09:51