Skip to content

Instantly share code, notes, and snippets.

@ntrepid8
Last active June 28, 2017 03:19
Show Gist options
  • Save ntrepid8/e2b052f292eede44df7d54b959fd8a08 to your computer and use it in GitHub Desktop.
Save ntrepid8/e2b052f292eede44df7d54b959fd8a08 to your computer and use it in GitHub Desktop.
Shell script to use with speedtest-cli and parse_speedtest_simple.py
#!/usr/bin/env bash
DATE_TAG="$(date -u +"%Y")-$(date -u +"%m")"
CSV_PATH="/home/$(whoami)/log/speedtest.$(hostname).${DATE_TAG}.csv"
LOG_PATH="/home/$(whoami)/log/speedtest.$(hostname).${DATE_TAG}.csv.log"
# ensure the path exists
mkdir -p $(dirname "${CSV_PATH}")
# add the header row if the file does not exist
if [ ! -f "${CSV_PATH}" ]; then
printf '"date_time","ping (ms)","download (Mbit/s)","upload (Mbit/s)"\n' >> "${CSV_PATH}"
fi
# run speedtest and record the results
if result=$(/usr/bin/speedtest --simple | parse_speedtest_simple.py); then
printf "${result}\n" >> "${CSV_PATH}"
else
printf "[$(date)] error\n" >> "${LOG_PATH}"
exit 1
fi
exit 0
@ntrepid8
Copy link
Author

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