I can see the download and upload speed for all interfaces using glances
. In the network
section we can see the Rx/s
and Tx/s
columns where I can see the value in Mbps
.
However I want to store this value in a variable. Is there any other command, which gives the current speed (bps
, or Kbps
, or Mbps
) so that I can save that value in a variable in a bash script ?
I want to do this for wlan0
interface.
There is not a single command to do this. However, you could use this:
On my system, currently, I get:
iwconfig wlan0
outputs a bunch of information aboutwlan0
(try it and see).Then
egrep
matches"Bit Rate="
, followed by 1 or more digits, a blank, and 1 or more non-blanks. Because of the-o
option,egrep
outputs only the matched string.sed
then changes the first blank to an underscore, the'='
to'="'
, and the end-of-line to'"'
, producing a string likeBit_Rate="54 Mb/s"
.eval
then interprets that string in your current shell.for further education, read