Skip to content

Instantly share code, notes, and snippets.

@San3-Cod3
Created December 8, 2022 05:14
Show Gist options
  • Save San3-Cod3/dfc039cb2bb2da0a3a6852a71be76027 to your computer and use it in GitHub Desktop.
Save San3-Cod3/dfc039cb2bb2da0a3a6852a71be76027 to your computer and use it in GitHub Desktop.
speedtest-cli — results you care about, returned ~ all on a single line; w/o the faff.
#!/bin/bash
# create/place in: /home/YOU/ or /usr/bin/ # ( sudo needed for latter ) #
# chmod +x speedtest-cli_jq_json.sh #
# sudo apt-get install -y jq speedtest-cli #
# ˇ jq explained simply @ link below ˇ #
# https://puu.sh/JslQO/c0d473928e.png #
# ˇ usage: ˇ #
# ./speedtest-cli_jq_json.sh # ( if in: /home/YOU/ ) #
# speedtest-cli_jq_json.sh # ( if placed in: /usr/bin/ ) #
# ˇ how snippet looks once executed ˇ #
# https://puu.sh/JslST/397941d6ca.png #
read p d u < <(\
speedtest-cli --json \
| jq -r '[.ping, .download/1000000, .upload/1000000] | join(" ")'
)
printf 'Ping: %.02f ms || Download: %.02f Mbit/s || Upload: %.02f Mbit/s\n' "$p" "$d" "$u"
@San3-Cod3
Copy link
Author

San3-Cod3 commented Dec 8, 2022

You can create an alias for this, e.g. st
This makes it quick and easy to use; you can make the alias permanent too
Add speedtest-cli_jq_json.sh as an alias in: /home/User.You/.bash_aliases -- if missing then create: .bash_aliases -- touch .bash_aliasses -- and then add inside .bash_aliases, the following line: alias st='/home/User.You/speedtest-cli_jq_json.sh'
Save it, and then afterwards do this: source ~/.bash_aliases
Then, to start speedtest-cli_jq_json.sh, from anywhere, just type: st and press Enter.

If you want to forgo the alias part, you can still start speedtest-cli_jq_json.sh from the directory its in by doing this: ./speedtest-cli_jq_json.sh

You might possibly need to make speedtest-cli_jq_json.sh executable, so to do that, type: chmod +x speedtest-cli_jq_json.sh

@San3-Cod3
Copy link
Author

ss (2022-11-23 at 04 44 00)
ss (2022-11-23 at 04 53 32)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment