Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Shell script to view system traffic in real time

Shulou Source: shulou.com Published: 2022-06-03 09:19:23 11月15日 Update

This article introduces the relevant knowledge of "how to use Shell scripts to view system traffic in real time". 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

This is the end of "how to use Shell script to view system traffic in real time". 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!

Tags: Real-time traffic system script content more knowledge practicality learning next code dilemma reality situation article case editing website industry process Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Huawei Shulou Information Apple Redmi vpn