Changes required because ss output now spans two lines

#!/bin/bash

# This script runs a bwctl test and, concurrently runs the 'ss' ("show socket" command),  
# at regular intervals during the test.  It is recommended the 'ss' interval be 0.1 or
# or 0.2 (seconds)
#
# The syntax of the command are:
# tcptest <target bwctl server> <length of test in sec> <'ss' frequency>
#
# The results are stored in two files in the user's home directory
# 1. tcp_test-<date/time of test>-<target host name>.results
# 2. stat_changes-<date/time of test>-<target host name>.results
#
# File 1 is a list of the 'ss' results, which should be graphed
# (with the use of a spreadsheet) for ease of interpretation.
# File 2 shows the difference between 'netstat -s' immediately before and after
# the bwctl test.  This is particularly useful for spotting TCP retransmissions etc

mkdir $HOME/temp

echo $1 >$HOME/temp/target.tmp
echo $2 > $HOME/temp/test_length.tmp
echo $3 > $HOME/temp/ss_int.tmp
test_port=5001
host=`uname -n`

echo "/$test_port/ {print \$0}" > $HOME/temp/awk_filter.tmp

test_length=`cat $HOME/temp/test_length.tmp`


netstat -s > $HOME/temp/stat_before.tmp
date +%y%m%d%H%M%S > $HOME/temp/time.tmp
test_time=`cat $HOME/temp/time.tmp`
(
test_time=`cat $HOME/temp/time.tmp`
target=`cat $HOME/temp/target.tmp`
test_length=`cat $HOME/temp/test_length.tmp`
test_interval=2
#echo $target
echo $test_time > $HOME/tcp_test-$test_time-$host.results

bwctl -c $target -t $test_length -i $test_interval >> $HOME/tcp_test-$test_time-$host.results
) &
(
# Sleep interval for 'ss'
ss_int=`cat $HOME/temp/ss_int.tmp`
test_length=`cat $HOME/temp/test_length.tmp`
bwctl_port=5001
test_time=`cat $HOME/temp/time.tmp`
echo $test_time > $HOME/temp/ss.tmp
uname -a >>  $HOME/temp/ss.tmp
cat $HOME/temp/target.tmp > $HOME/temp/ss.tmp
testIterations=`echo "($test_length + 10) / $ss_int" | bc`

for ((i=0; i<$testIterations; i++))
do
        testTimeNow=`echo "$i * $ss_int" | bc`
        echo -n $testTimeNow $'\t' >> $HOME/temp/ss.tmp
        /usr/sbin/ss -i dport eq :5001 | sed -e '1 d' -e '/./N;s_\n *_ _' >> $HOME/temp/ss.tmp
        echo "" >> $HOME/temp/ss.tmp
        sleep $ss_int
done
)
wait
netstat -s > $HOME/temp/stat_after.tmp
target=`cat $HOME/temp/target.tmp`
ping -c 3 $target >> $HOME/tcp_test-$test_time-$host.results

# This filters out lines without '5001' on them
awk -f  $HOME/temp/awk_filter.tmp $HOME/temp/ss.tmp>> $HOME/tcp_test-$test_time-$host.results
head -n 20 $HOME/tcp_test-$test_time-$host.results
diff $HOME/temp/stat_before.tmp $HOME/temp/stat_after.tmp > $HOME/stat_changes-$test_time-$host.results

# Tidy up
rm $HOME/temp/*.tmp
rmdir $HOME/temp

exit 0

-- TobyRodwell - 06 Feb 2007

Topic revision: r1 - 2007-02-06 - TobyRodwell
 
This site is powered by the TWiki collaboration platform Powered by PerlCopyright © 2004-2009 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.