#!/bin/bash
in_old=$(cat /proc/net/dev | grep eth0 | sed 's=^.*:==' | awk '{print $1}')
out_old=$(cat /proc/net/dev | grep eth0 | sed 's=^.*:==' | awk '{print $9}')
while true
do
sleep 1
in=$(cat /proc/net/dev | grep eth0 | sed 's=^.*:==' | awk '{print $1}')
out=$(cat /proc/net/dev | grep eth0 | sed 's=^.*:==' | awk '{print $9}')
dif_in=$((in-in_old))
if [ $dif_in -lt 1024 ]
then
dif_in1="$((dif_in)) B/s"
elif [ $dif_in -gt 1048576 ]
then
dif_in1="$((dif_in/1024/1024)) MB/s"
else
dif_in1="$((dif_in/1024)) KB/s"
fi
dif_out=$((out-out_old))
if [ $dif_out -lt 1024 ]
then
dif_out1="$((dif_out)) B/s"
elif [ $dif_out -gt 1048576 ]
then
dif_out1="$((dif_out/1024/1024)) MB/s"
else
dif_out1="$((dif_out/1024)) KB/s"
fi
echo "IN:${dif_in1} OUT:${dif_out1}"
in_old=${in}
out_old=${out}
done