count-packets.sh
#!/bin/bash
#
# 2008 Oliver Voelker <info(at)ovtec.it>
#
# Pakete pro Sekunde fuer ein bestimmtes Interface ermitteln
#
if [ -z $1 ]; then
echo "Usage: $0 <interface> [<time>]"
echo "Default measure time is 10 seconds"
exit 0
fi
if [ -z $2 ]; then
TIME=10
else
TIME=$2
fi
DEV=$1
RUN=`ifconfig $DEV | grep "X packets"`
if [ $? -ne 0 ]; then
echo "Fehler!"
exit 1
fi
RX1=`echo $RUN | cut -d" " -f2 | cut -d":" -f2`
TX1=`echo $RUN | cut -d" " -f8 | cut -d":" -f2`
#echo "RX-1: $RX1"
#echo "TX-1: $TX1"
sleep $TIME
RUN=`ifconfig $DEV | grep "X packets"`
if [ $? -ne 0 ]; then
echo "Fehler!"
exit 1
fi
RX2=`echo $RUN | cut -d" " -f2 | cut -d":" -f2`
TX2=`echo $RUN | cut -d" " -f8 | cut -d":" -f2`
#echo "RX-2: $RX2"
#echo "TX-2: $TX2"
RX=$(($RX2 - $RX1))
TX=$(($TX2 - $TX1))
RXps=$(($RX / $TIME))
TXps=$(($TX / $TIME))
echo "RX in $TIME seconds: $RX (RX per second: $RXps)"
echo "TX in $TIME seconds: $TX (TX per second: $TXps)"
No Comments