一个显示实时网速代码
160 字
1 分钟
一个显示实时网速代码
显示实时网速
#!/bin/bashwhile [ "1" ]doeth=$1RXpre=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}')TXpre=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}')sleep 1RXnext=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $2}')TXnext=$(cat /proc/net/dev | grep $eth | tr : " " | awk '{print $10}')clearecho -e "\t RX `date +%k:%M:%S` TX"RX=$((${RXnext}-${RXpre}))TX=$((${TXnext}-${TXpre}))
if [[ $RX -lt 1024 ]];thenRX="${RX}B/s"elif [[ $RX -gt 1048576 ]];thenRX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')elseRX=$(echo $RX | awk '{print $1/1024 "KB/s"}')fi
if [[ $TX -lt 1024 ]];thenTX="${TX}B/s"elif [[ $TX -gt 1048576 ]];thenTX=$(echo $TX | awk '{print $1/1048576 "MB/s"}')elseTX=$(echo $TX | awk '{print $1/1024 "KB/s"}')fi
echo -e "$eth \t $RX $TX "done执行 ./top.sh eth0.即可 ,eth0看你的网卡名
文章分享
如果这篇文章对你有帮助,欢迎分享给更多人!














