Archive for March 1st, 2007

A Simple Linux Bandwidth Meter Using sed

Well, I was bored yesterday and I came up with this:

getdata() {
    DATA=`ifconfig eth0|sed -n 's/\( *RX bytes:\)\([0-9]*\)\([^:]*\):\([0-9]*\)\(.*)\)/\2 \4/p'`
    RX=`echo $DATA|sed -n 's/\([0-9]*\) \(.*\)/\1/p'`
    TX=`echo $DATA|sed -n 's/\([^ ]*\) \(.*\)/\2/p'`
}
getdata
while true; do
    OLDRX=$RX
    OLDTX=$TX
    getdata
    echo -n -e "\fRX: $((RX-OLDRX)) B/s\nTX: $((TX-OLDTX)) B/s"
    sleep 1
done

What it does is call ifconfig eth0 every second, and compare the total number of bytes received and transmitted up to the previous second, with the number up to this second. The difference is, well, the number of bytes transferred this second. It’s a cheap network usage monitor. :)


 

March 2007
M T W T F S S
« Feb   Apr »
 1234
567891011
12131415161718
19202122232425
262728293031  

a

Reverse

To reverse the order of the entries (chronogical top-to-bottom), paste this into your address bar, and hit Enter: