old blog,

Bandwidth Monitoring Script (through ifconfig)

Izhar Firdaus Izhar Firdaus Follow Support Mar 14, 2006 · 1 min read
Bandwidth Monitoring Script (through ifconfig)
Creative Commons License
This work is licensed under a Creative Commons Attribution 4.0 International License.

Some ppl might need sumthing to monitor their bwidth … i think this script would b enough for some of us … i wrote it by myself by manipulating the output of ifconfig …



#!/bin/bash

IFCONFIG="/sbin/ifconfig”
IFACE=$1
if [ “${1}” != “” ]; then
IFOUTPUT=`${IFCONFIG} ${IFACE} |grep bytes`
DOWNOLD=`echo ${IFOUTPUT}|awk ‘{print $2}’|sed s/"bytes:"//`
UPOLD=`echo ${IFOUTPUT}|grep bytes|awk ‘{print $6}’|sed s/"bytes:"//`
sleep 0.8
IFOUTPUT=`${IFCONFIG} ${IFACE} |grep bytes`
DOWNNOW=`echo ${IFOUTPUT}|awk ‘{print $2}’|sed s/"bytes:"//`
UPNOW=`echo ${IFOUTPUT}|awk ‘{print $6}’|sed s/"bytes:"//`

let “UP= $UPNOW - $UPOLD”
let “DOWN= $DOWNNOW - $DOWNOLD”
let “TOTAL = UP + DOWN”
echo “—-KBps Bandwitdh Monitor—-”
echo “”
echo ” by KageSenshi”
echo “”
echo “”
echo “——————————”
echo “Bandwidth for Interface ${IFACE}”
echo “——————————”
echo “”
echo ” KBps MBps”
echo “Upload Speed $(($UP / 1024)) $(($UP / 1024 / 1024))”
echo “Download Speed $(($DOWN / 1024)) $(($DOWN / 1024 / 1024))”
echo ” Total $(($TOTAL / 1024)) $(($TOTAL / 1024 /1024))”
echo “”

# uncomment this if u want the output to be stored in ur hdd
# echo “${UP} ${DOWN} ${TOTAL}” >> $HOME/bwidth.txt

echo “”
echo “*Tips : View this in realtime”
echo ” watch -d=c bwmon ${IFACE} “
else
echo “Bandwitdh Monitor “
echo “By: KageSenshi “
echo ” “
echo “Usage:”
echo ” bwmon
echo ” watch -d=n bwmon
fi

Written by Izhar Firdaus Follow Support
I'm a system architect, data engineer and developer advocate with passion in Free / Open Source software, entrepreneurship, community building, education and martial art. I take enjoyment in bridging and bringing together different FOSS technologies to help businesses and organizations utilize IT infrastructure to aid and optimize their business and organizational process.

Linux vs Windows Viruses

An article about Linux and Windows viruses and why Linux is more secure when against automated e-mail bourne viruses... To mess up...

In old blog, Feb 12, 2006

« Previous Post

Thin Client Project - juz for fun ....

i’m currently exploring the thin client technology for implementing it at my home ... in case any of you dont know the meaning of thi...

In old blog, May 16, 2006

Next Post »