Created
April 30, 2019 00:16
-
-
Save tapickell/9230812c923494f723686436d2dd2f4f to your computer and use it in GitHub Desktop.
net_speed of one nic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
SLP=1 # output / sleep interval | |
DEVICE=$1 | |
IS_GOOD=0 | |
for GOOD_DEVICE in `grep \: /proc/net/dev | awk -F: '{print $1}'`; do | |
if [ "$DEVICE" = $GOOD_DEVICE ]; then | |
IS_GOOD=1 | |
break | |
fi | |
done | |
if [ $IS_GOOD -eq 0 ]; then | |
echo "Device not found. Should be one of these:" | |
grep ":" /proc/net/dev | awk -F: '{print $1}' | sed s@\ @@g | |
exit 1 | |
fi | |
while true; do | |
LINE=`grep $1 /proc/net/dev | sed s/.*://`; | |
RECEIVED1=`echo $LINE | awk '{print $1}'` | |
TRANSMITTED1=`echo $LINE | awk '{print $9}'` | |
TOTAL=$(($RECEIVED1+$TRANSMITTED1)) | |
sleep $SLP | |
LINE=`grep $1 /proc/net/dev | sed s/.*://`; | |
RECEIVED2=`echo $LINE | awk '{print $1}'` | |
TRANSMITTED2=`echo $LINE | awk '{print $9}'` | |
SPEED=$((($RECEIVED2+$TRANSMITTED2-$TOTAL)/$SLP)) | |
INSPEED=$((($RECEIVED2-$RECEIVED1)/$SLP)) | |
OUTSPEED=$((($TRANSMITTED2-$TRANSMITTED1)/$SLP)) | |
printf "\033c" | |
printf "In: %12i KB/s | Out: %12i KB/s | Total: %12i KB/s\n" $(($INSPEED/1024)) $(($OUTSPEED/1024)) $((($INSPEED+$OUTSPEED)/1024)) ; | |
done; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment