Linux, FreeBSD, Juniper, Cisco / Network security articles and troubleshooting guides

FAQ
It is currently Wed Dec 06, 2023 9:12 am


Username:
Subject:
Message body:
Enter your message here, it may contain no more than 60000 characters. 

Smilies
:D :) ;) :( :o :shock: :? 8-) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :!: :?: :idea: :arrow: :| :mrgreen: :geek: :ugeek:
Font size:
 
Font colour
Options:
BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON
Disable BBCode
Disable smilies
Do not automatically parse URLs
Confirmation code
Confirmation code:
In an effort to prevent automatic submissions, we require that you enter both of the words displayed into the text field underneath.
     

Topic review - Linux script for interface network bandwidth monitoring
Author Message
Post subject: Linux script for interface network bandwidth monitoring  |  Post Posted: Mon Feb 09, 2015 7:05 pm
This is a simple script that gets RX / TX values of an interface from /sys pseudo filesystem and calculate difference between current and old values displaying a bandwidth output for kilobytes per second.
Code:
#!/bin/bash
INT="1"  # every INT seconds

while true
do
        RX1=`cat /sys/class/net/$1/statistics/rx_bytes`
        TX1=`cat /sys/class/net/$1/statistics/tx_bytes`
        sleep $INT
        RX2=`cat /sys/class/net/$1/statistics/rx_bytes`
        TX2=`cat /sys/class/net/$1/statistics/tx_bytes`
        TXBPS=`expr $TX2 - $TX1`
        RXBPS=`expr $RX2 - $RX1`
        TXKBPS=`expr $TXBPS / 1024`
        RXKBPS=`expr $RXBPS / 1024`
        echo "TX $1: $TXKBPS kb/s RX $1: $RXKBPS kb/s"
done
Jump to:  
cronNews News Site map Site map SitemapIndex SitemapIndex RSS Feed RSS Feed Channel list Channel list


Delete all board cookies | The team | All times are UTC - 5 hours [ DST ]



phpBB SEO