Skip to content

Instantly share code, notes, and snippets.

@Juma7C9
Created October 12, 2013 20:54
Show Gist options
  • Save Juma7C9/6954815 to your computer and use it in GitHub Desktop.
Save Juma7C9/6954815 to your computer and use it in GitHub Desktop.
Simple real time network traffic monitor
#!/bin/bash
# net_speed.sh -- A simple real time network traffic monitor
# USAGE: net_speed.sh interface
# Copyright (C) 2013 Juma7C9
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
interface=$1
if [ -z $interface ]
then
echo "usage: $0 interface"
exit 0
fi
if [[ ! -e /sys/class/net/$interface ]]
then
echo "[ERROR] interface $interface not found!"
exit 0
fi
while true
do
TXi=`cat /sys/class/net/$interface/statistics/tx_bytes`
RXi=`cat /sys/class/net/$interface/statistics/rx_bytes`
sleep 1
TXf=`cat /sys/class/net/$interface/statistics/tx_bytes`
RXf=`cat /sys/class/net/$interface/statistics/rx_bytes`
let "DTX=$TXf-$TXi"
let "DRX=$RXf-$RXi"
kTX=`expr $DTX / 1024`
kRX=`expr $DRX / 1024`
time=`date +%T`
echo "$time ($interface): TX: $kTX KiB/s, RX: $kRX KiB/s"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment