#!/bin/ksh
set -x
if [ $# -lt 1 ];then
	echo "Usage: $0 <multiples of 5 seconds to run for>"
else
	THEN=`date`

	# Get some initial values
	for INT in 1.1 1.2
		do
		for STATS in `b interface $INT show verbose | awk '/packets in/{print $1}/packets out/{print $1}'`
		do
			if [ -z "$IN" ];then
				`echo ${INT}_IN_COUNTER`=$STATS
				IN=A
			else
				${INT}_OUT_COUNTER=$STATS
			fi
		done
	done

	echo "Started watching at $THEN..."
	LOOP=0
	while [ $LOOP -ne $1 ]
	do
		for INT in 1.1 1.2
		do
			IN=""
			for STATS in `b interface $INT show verbose | awk '/packets in/{print $1}/packets out/{print $1}'`
			do
				if [ -z "$IN" ];then
					echo "Interface $INT has received $((${$INT_IN_COUNTER}-$STATS)) packets since $THEN"
					$INT_IN_COUNTER=$STATS
					IN=A
				else
					echo "Interface $INT has sent $((${$INT_OUT_COUNTER}-$STATS)) packets since $THEN"
					$INT_OUT_COUNTER=$STATS
				fi
			done

		done
		sleep 5
		LOOP=$(($LOOP+1))
	done
fi