Skip to content

Instantly share code, notes, and snippets.

@mayronceccon
Last active February 1, 2023 21:35
Show Gist options
  • Select an option

  • Save mayronceccon/c3dc6285c9c9d850ebb8223d46620ba6 to your computer and use it in GitHub Desktop.

Select an option

Save mayronceccon/c3dc6285c9c9d850ebb8223d46620ba6 to your computer and use it in GitHub Desktop.
#!/bin/bash
# install dependencies
# sudo apt-get install curl
# curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash
# sudo apt-get update
# sudo apt-get install wireless-tools
# sudo apt-get install jq
# sudo apt-get install speedtest
echo "START"
FILE="./speedtest.csv"
if [ ! -f "$FILE" ]; then
echo "FILE NOT EXIST"
echo "timestamp;download;upload;ping;download_latency;upload_latency;wifi;wifi_frequency;server;result" > $FILE
fi
RUN_AFTER_MINUTES=15
SLEEP=$((60*RUN_AFTER_MINUTES))
while true
do
echo "RUN SCRIPT"
WIFI_NAME=$(iwgetid -r)
WIFI_FREQUENCY=$(iwgetid -r -f)
speedtest -p no -f json -s 37923 | jq '. | {timestamp: now|strflocaltime("%Y-%m-%d %H:%M:%S"), download: ((((.download.bandwidth / 125000)*100)|round)/100), upload: ((((.upload.bandwidth / 125000)*100)|round)/100), ping: .ping.latency|round, download_latency: .download.latency.iqm|round, upload_latency: .upload.latency.iqm|round, wifi: "WIFI_NAME", wifi_frequency: "WIFI_FREQUENCY", server: .server.host, result: .result.url} | join(";")' | sed -r 's/"//g' | sed -r "s/WIFI_NAME/${WIFI_NAME}/g" | sed -r "s/WIFI_FREQUENCY/${WIFI_FREQUENCY}/g" >> $FILE
echo "WAITING"
sleep $SLEEP
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment