Skip to content

Instantly share code, notes, and snippets.

@maxisme maxisme/5Gmonitor.sh

Last active Feb 26, 2020
Embed
What would you like to do?
Tweet speeds of 5G router in E1
#!/bin/bash
# Maximilian Mitchell (max.me.uk)
# cron:
# 0 * * * * /usr/bin/curl -s https://gist.githubusercontent.com/maxisme/ea9bfe4cfcf5b89494a7a793253b8a60/raw/5Gmonitor.sh | bash
# requirements:
# - jq
# - speedtest
# - t
EXPECTED_DL=400
EXPECTED_UL=40
# run ookla speedtest
servers=(15815 24281 11445 8066 24383 12920 11123 6151) # list of servers to test with
random_server=${servers[$RANDOM % ${#servers[@]}]}
echo $random_server
speedtest=$(speedtest -f json -s $random_server)
# parse output of speed test
ping=$(echo "$speedtest" | jq -r ".ping.latency")
dl=$(echo "$speedtest" | jq -r ".download.bandwidth")
dlmbits="$(($dl / 125000))"
ul=$(echo "$speedtest" | jq -r ".upload.bandwidth")
ulmbits="$(($ul / 125000))"
server_host=$(echo "$speedtest" | jq -r ".server.host")
server_name=$(echo "$speedtest" | jq -r ".server.name")
link=$(echo "$speedtest" | jq -r ".result.url")
if [[ -z $ping || "$ping" == "null" ]]
then
# speedstest failed
t update "$speedtest" -P /root/.trc
exit
fi
curl "https://5gmonitor.ml/api?download=$dlmbits&upload=$ulmbits&ping=$ping&secret=$SECRET_KEY"
dlmood="😁"
if (( $dlmbits < $EXPECTED_DL )); then
dlmood="😩"
fi
ulmood="😁"
if (( $ulmbits < $EXPECTED_UL )); then
ulmood="😩"
fi
# format tweet
tweet="#download: ${dlmbits}Mbit/s $dlmood
#upload: ${ulmbits}Mbit/s $ulmood
#ping: $ping
#server: $server_host ($server_name)
#three #broadband #speed #5G #E1 #ookla #london #Real5G"
# send tweet
t update "$tweet" -P /root/.trc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.