#!/bin/bash if [ "X$1" = "X-v" ] then verbose=true; shift else verbose=false fi dev=${1:-eth0} previous=$(/sbin/ifconfig $dev | sed -n 's/.*RX bytes:\([0-9]*\) .*TX bytes:\([0-9]*\) .*/\1 \2/p') rxprevious=${previous%% [0-9]*} txprevious=${previous##[0-9]* } while true do sleep 10 current=$(/sbin/ifconfig $dev | sed -n 's/.*RX bytes:\([0-9]*\) .*TX bytes:\([0-9]*\) .*/\1 \2/p') rxcurrent=${current%% [0-9]*} txcurrent=${current##[0-9]* } if [ $rxcurrent -ge $rxprevious ] then rx=$(( $rxcurrent - $rxprevious )) else rx=$(( 2 ** 32 - $rxprevious + $rxcurrent )) fi if [ $txcurrent -ge $txprevious ] then tx=$(( $txcurrent - $txprevious )) else tx=$(( 2 ** 32 - $txprevious + $txcurrent )) fi rx=$(( $rx / 10 )) tx=$(( $tx / 10 )) rxu=' ' txu=' ' if [ $rx -ge 10000 ] then rxu=k; rx=$(( $rx / 1000 )) fi if [ $tx -ge 10000 ] then txu=k; tx=$(( $tx / 1000 )) fi if [ $rx -ge 10000 ] then rxu=M; rx=$(( $rx / 1000 )) fi if [ $tx -ge 10000 ] then txu=M; tx=$(( $tx / 1000 )) fi printf "RX %5sB/s TX %5sB/s" "${rx}${rxu}" "${tx}${txu}" $verbose && printf "\t\trx:%10lu\ttx:%10lu" $rxcurrent $txcurrent printf "\n" rxprevious=$rxcurrent txprevious=$txcurrent done