#!/bin/bash

net_dev=$1

while true; do
  OLD=$NEW;
  NEW=$(cat /proc/net/dev | grep $net_dev | tr -s ' ' | cut -d' ' -f "3 11");
  echo $NEW $OLD | awk '{
    in_diff=($1-$3)/1024; out_diff=($2-$4)/1024;
    unit="KB";
    if (in_diff>=1024) {in_diff/=1024; unit="MB";}
    if (out_diff>=1024) {out_diff/=1024; if (unit=="MB") unit="MB";}
    printf("\rin: % 9.2f %s\t\tout: % 9.2f %s", in_diff, unit, out_diff, unit)
  }';
  sleep 1;
done
