Sunday, May 5, 2024
15
rated 0 times [  15] [ 0]  / answers: 1 / hits: 15016  / 1 Year ago, tue, march 7, 2023, 2:09:22

I want the terminal to output the current upload and download speeds of my network connection. I do not want to monitor the speeds in real time. I just want a "static" value to be able to write it in a file.



How do I achieve it?


More From » command-line

 Answers
5

Oddly the easiest way seems to be looking at /proc/net/dev. I've written the following to compare that file twice (with a second delay) and then to subtract the total bytes values. In this case em1 is the network adaptor so just change that to whatever you need to look at.



awk '/em1/ {i++; rx[i]=$2; tx[i]=$10}; END{print rx[2]-rx[1] " " tx[2]-tx[1]}' 
<(cat /proc/net/dev; sleep 1; cat /proc/net/dev)


The output is two numbers. Received bytes per second followed by sent bytes per second.


[#25888] Wednesday, March 8, 2023, 1 Year  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
uccase

Total Points: 473
Total Questions: 100
Total Answers: 110

Location: Anguilla
Member since Sun, Jan 29, 2023
1 Year ago
uccase questions
;