Thursday, December 27, 2007

A small and stupid one liner for seeing the instantaneous bandwidth


Disclaimer: May or may not work for you. Use a bash shell or make necessary changes to support any other. There may be many other ways of doing this efficiently.

Usage :
- Edit the variables int and dir as desired.
- dir = RX will calculate download speed
dir = TX wil calculate upload speed.
- Cutpaste the one liner as is on a bash shell.

int="eth1"; dir="RX"; oldbytes=0; while [ 1 ]; do bytes=`ifconfig $int | grep "$dir bytes" | awk '{print $2}' | awk 'BEGIN {FS=":"} {print $2}'`; bw=`expr $bytes - $oldbytes`; bw=`expr $bw \* 8`; bw=`expr $bw / 1024`; oldbytes=$bytes; sleep 1; echo "$bw Kb/s"; done

Use of the above : Left to the readers imagination.

No comments: