#! /bin/bash
eth="br-lan"
timer=1
# Setting IFS (input field separator) value as ","
IFS=' '
# Reading the split string into array
read -ra arr <<< "$(cat /proc/net/dev | grep $eth)"
in_old=${arr[1]}
out_old=${arr[9]}
while true
do
sleep ${timer}
read -ra arr <<< "$(cat /proc/net/dev | grep $eth)"
in=${arr[1]}
out=${arr[9]}
dif_in=$(((in-in_old)/timer))
#dif_in=$((dif_in/102400))
dif_in=$(echo | awk "{print $dif_in/131072}" )
dif_out=$(((out-out_old)/timer))
#dif_out=$((dif_out/102400))
dif_out=$(echo | awk "{print $dif_out/131072}" )
printResult=$(echo ${dif_in}","${dif_out})
echo $printResult > DashBoard.txt
ct=$(date +"%F %H:%M:%S")
echo "${ct} -- DownLink: ${dif_in} Mbit/s UpLink: ${dif_out} Mbit/s"
in_old=${in}
out_old=${out}
done
exit 0
标签:Mbit,shell,old,IFS,网卡,速率,ct,out
From: https://www.cnblogs.com/o-O-oO/p/18468003