Network interface speed shell script

A shell script to determine the current throughput of a network interface. Yay!
#!/bin/sh
dev=$1
if test "$dev" = ""
then
echo "No link specified. Using eth0"
dev="eth0"
fi

inA=`ip -s link show $dev | tail -n3 | head -n1 | tr -s " " | cut -d" " -f2`
outA=`ip -s link show $dev | tail -n1 | tr -s " " | cut -d" " -f2`
sleep 2
inB=`ip -s link show $dev | tail -n3 | head -n1 | tr -s " " | cut -d" " -f2`
outB=`ip -s link show $dev | tail -n1 | tr -s " " | cut -d" " -f2`
echo "RX: $[(($inB-$inA)*8)/1000] kbps"
echo "TX: $[(($outB-$outA)*8)/1000] kbps"


Comments: Post a Comment

<< Home

This page is powered by Blogger. Isn't yours?