Linux中如何编写脚本实时检测网络接口速度?

2026-05-26 14:361阅读0评论SEO资源
  • 内容介绍
  • 文章标签
  • 相关推荐

本文共计301个文字,预计阅读时间需要2分钟。

Linux中如何编写脚本实时检测网络接口速度?

修改后的脚本文件+


修改后的脚本文件


#!/bin/bash
#Modified by lifei4@datangmobile.cn
echo ===DTmobile NetSpeedMonitor===
sleep 1
echo loading...
sleep 1

ethn=$1

while true
do
RXpre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
TXpre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
sleep 1
RXnext=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
TXnext=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')

clear
echo -e "\t\t\t RX \t\t TX \t\t\t TIME"

RX=$((RXnext-RXpre))
TX=$((TXnext-TXpre))

if [ $RX -lt 1024 ];then
RX="${RX}B/s"
elif [ $RX -gt 1048576 ];then
RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')
else
RX=$(echo $RX | awk '{print $1/1024 "KB/s"}')
fi

if [ $TX -lt 1024 ];then
TX="${TX}B/s"
elif [[ $TX -gt 1048576 ]];then
TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}')
else
TX=$(echo $TX | awk '{print $1/1024 "KB/s"}')
fi

echo -e "$ethn \t $RX $TX \t\t\t `date +%k:%M:%S` "

done


Linux中如何编写脚本实时检测网络接口速度?

用法

./NetSpeedMonitor.sh



最终结果展示




更多内容详见微信公众号:Python研究所



标签:shell

本文共计301个文字,预计阅读时间需要2分钟。

Linux中如何编写脚本实时检测网络接口速度?

修改后的脚本文件+


修改后的脚本文件


#!/bin/bash
#Modified by lifei4@datangmobile.cn
echo ===DTmobile NetSpeedMonitor===
sleep 1
echo loading...
sleep 1

ethn=$1

while true
do
RXpre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
TXpre=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')
sleep 1
RXnext=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $2}')
TXnext=$(cat /proc/net/dev | grep $ethn | sed 's/:/ /g' | awk '{print $10}')

clear
echo -e "\t\t\t RX \t\t TX \t\t\t TIME"

RX=$((RXnext-RXpre))
TX=$((TXnext-TXpre))

if [ $RX -lt 1024 ];then
RX="${RX}B/s"
elif [ $RX -gt 1048576 ];then
RX=$(echo $RX | awk '{print $1/1048576 "MB/s"}')
else
RX=$(echo $RX | awk '{print $1/1024 "KB/s"}')
fi

if [ $TX -lt 1024 ];then
TX="${TX}B/s"
elif [[ $TX -gt 1048576 ]];then
TX=$(echo $TX | awk '{print $1/1048576 "MB/s"}')
else
TX=$(echo $TX | awk '{print $1/1024 "KB/s"}')
fi

echo -e "$ethn \t $RX $TX \t\t\t `date +%k:%M:%S` "

done


Linux中如何编写脚本实时检测网络接口速度?

用法

./NetSpeedMonitor.sh



最终结果展示




更多内容详见微信公众号:Python研究所



标签:shell