Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use Shell script to view real-time traffic of network card

2025-03-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article introduces the knowledge of "how to use Shell script to view the real-time traffic of network card". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

The code is as follows:

#! / bin/bash

While ["1"]

Do

Eth=$1

RXpre=$ (cat / proc/net/dev | grep $eth | tr: "" | awk'{print $2}')

TXpre=$ (cat / proc/net/dev | grep $eth | tr: "" | awk'{print $10}')

Sleep 1

RXnext=$ (cat / proc/net/dev | grep $eth | tr: "" | awk'{print $2}')

TXnext=$ (cat / proc/net/dev | grep $eth | tr: "" | awk'{print $10}')

Clear

Echo-e "\ t RX `date +% KRV% M:% S` TX"

RX=$ ((${RXnext}-${RXpre}))

TX=$ ((${TXnext}-${TXpre}))

If [$RX-lt 1024]; then

RX= "${RX} Bamp s"

Elif [$RX-gt 1048576]; then

RX=$ (echo $RX | awk'{print $1max 1048576 "MB/s"}')

Else

RX=$ (echo $RX | awk'{print $1amp 1024 "KB/s"}')

Fi

If [$TX-lt 1024]; then

TX= "${TX} Bamp s"

Elif [$TX-gt 1048576]; then

TX=$ (echo $TX | awk'{print $1max 1048576 "MB/s"}')

Else

TX=$ (echo $TX | awk'{print $1amp 1024 "KB/s"}')

Fi

Echo-e "$eth\ t $RX $TX"

Done

Call method:

The code is as follows:

. / traff.sh eth2

Or

Bash traff.sh eth2

The network card traffic can be displayed in real time:

This is the end of the content of "how to use Shell script to view network card real-time traffic". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report