I'd like to periodically display my speedtest download speed result in indicator-sysmonitor.
speedtest-cli has a somewhat trimmed output if you run
$ speedtest-cli --simple
Ping: 50.808 ms
Download: 10.87 Mbit/s
Upload: 4.47 Mbit/s
Is there any way to trim the output even more, down to just the download speed numeral?
That's a job for
awk
:Explanations
NR==2
– take line2
{print$2}
– print the second column (space-separated by default){print$2" "$3}
– print the second column followed by a space and the third oneWith
sed
it's a little more complicated:Explanations
/D/!d
– search for lines containingD
and don't (!
)d
elete them, but every other lines/A/B/
–s
ubstituteA
withB
.*
– take everything[^ ]*
– take everything that's not (^
) a space␣
(space character) – a literal space\(…\)
- take everything inside and save it as a group\1
– get the content of group 1As
speedtest-cli
is a python program and library it's fairly easy to make a minimal alternative program that only performs a download test and prints the output.Open an editor, save as
dl-speedtest.py
run with
python dl-speedtest.py
This gives the result in
bps, as a floating point numberMbps rounded to one decimal as requestedThe minimal version of speedtest-cli for this to work is 1.0.0 I think, you may need to use
pip install speedtest-cli --upgrade
to upgrade.You can try this:
This will also work:
And then there's:
Like dessert's first option though without the line selector.