flat assembler
Message board for the users of flat assembler.

Index > Linux > rx/tx eth0 monitor

Author
Thread Post new topic Reply to topic
sylware



Joined: 23 Oct 2020
Posts: 437
Location: Marseille/France
sylware 20 Jul 2023, 14:45
Pre-requisites:

/run/user/user_id directory
terminal "clear" command may be busybox only (it is what I run). I should use the terminal ANSI escape code.
Should run in dash shell too (avoid bash like hell of course, don't be corpo naughty).

Code:
#!/bin/sh
f0=$(mktemp -p /run/user/$(id -u) -u)

cleanup ()
{
        rm -f $f0 
        exit
}

trap cleanup 2

cp -f /proc/net/dev $f0
receive_prev=$(grep -F eth0 $f0  | cut -F 3)
transmit_prev=$(grep -F eth0 $f0  | cut -F 11)

sleep 10

while true
do
        cp -f /proc/net/dev $f0
        receive_new=$(grep -F eth0 $f0  | cut -F 3)
        transmit_new=$(grep -F eth0 $f0  | cut -F 11)

        clear
        printf "RECEIVE:$(( ($receive_new - $receive_prev)*8/10000 ))\n"
        printf "TRANSMIT:$(( ($transmit_new - $transmit_prev)*8/10000 ))"

        receive_prev=$receive_new
        transmit_prev=$transmit_new

        sleep 10
done
    
Post 20 Jul 2023, 14:45
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.