11
May
05

BandWidth bash function

Added to the recursos.sh script a function for the bandwidth. You need to define $DEV and then run the function the first time to create the neccesary file, then you can run it every 5 minutes for example :)

ibw () {
DEV=eth0
if [ -f /tmp/bw-$DEV.tmp ]; then
set — $(cat /tmp/bw-$DEV.tmp)
OLDSEC=$1
OLDRX=$(($2*8/1024))
OLDTX=$(($3*8/1024))
set — $(ifconfig $DEV | gawk ‘/RX bytes/{print $2,$6}’ | sed ‘s/bytes://g’)
NEWRX=$(($1*8/1024))
NEWTX=$(($2*8/1024))
NEWSEC=$(date +%s)

RX=$((($NEWRX-$OLDRX)/($NEWSEC-$OLDSEC)))
TX=$((($NEWTX-$OLDTX)/($NEWSEC-$OLDSEC)))
echo $RX $TX

echo $NEWSEC > /tmp/bw-$DEV.tmp
echo $1 >> /tmp/bw-$DEV.tmp
echo $2 >> /tmp/bw-$DEV.tmp

else
## Create file with first timstamp
set — $(ifconfig $DEV | gawk ‘/RX bytes/{print $2,$6}’ | sed ‘s/bytes://g’)
date +%s > /tmp/bw-$DEV.tmp
echo $1 >> /tmp/bw-$DEV.tmp
echo $2 >> /tmp/bw-$DEV.tmp
fi

}

Advertisements

2 Responses to “BandWidth bash function”


  1. 1 robbat2
    11 May, 2005 at 12:22 pm

    go and have a look at ipaudit. I use it to do much larger scale traffic auditing stuff.

  2. 16 May, 2005 at 21:08 pm

    thanks robbat :)
    so i need more than a BW monitor and i need it in a only way (client->server)


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


del.icio.us

Flickr Photos


%d bloggers like this: