#!/bin/sh if [ "$1" = "" ]; then echo "Please provide one of the following interfaces as a parameter: (ie. ./iftop.sh eth0)" grep -v lo /proc/net/dev | grep -v Inter | grep -v face | awk '{print $1}' | tr -d ':' exit 1 fi LASTRX=$(grep "$1" /proc/net/dev | awk '{print $2}') LASTTX=$(grep "$1" /proc/net/dev | awk '{print $10}') printf "%9s %12s %12s\n" "Interface" "Received" "Transmitted" echo "------------------------------------" LINES=0 while :; do sleep 1 LINES=$((LINES+1)) RX=$(grep "$1" /proc/net/dev | awk '{print $2}') TX=$(grep "$1" /proc/net/dev | awk '{print $10}') RXDIFF=$(($RX-$LASTRX)) TXDIFF=$(($TX-$LASTTX)) LASTRX=$RX LASTTX=$TX if [ $RXDIFF -gt $((1024*1024*1024)) ]; then RXMOD="GB/s" RXDIFF=$((RXDIFF/1024/1024/1024)) elif [ $RXDIFF -gt $((1024*12024)) ]; then RXMOD="MB/s" RXDIFF=$((RXDIFF/1024/1024)) elif [ $RXDIFF -gt 1024 ]; then RXMOD="KB/s" RXDIFF=$((RXDIFF/1024)) else RXMOD="Bytes/s" fi if [ $TXDIFF -gt $((1024*1024*1024)) ]; then TXMOD="GB/s" TXDIFF=$((TXDIFF/1024/1024/1024)) elif [ $TXDIFF -gt $((1024*12024)) ]; then TXMOD="MB/s" TXDIFF=$((TXDIFF/1024/1024)) elif [ $TXDIFF -gt 1024 ]; then TXMOD="KB/s" TXDIFF=$((TXDIFF/1024)) else TXMOD="Bytes/s" fi if [ $LINES -eq 20 ]; then echo printf "%9s %12s %12s\n" "int" "Received" "Transmitted" echo "------------------------------------" LINES=0 fi printf "%9s %4s %7s %4s %7s\n" $1 $RXDIFF $RXMOD $TXDIFF $TXMOD done