From fec307843b427e25e3de0b39e8f586427f78fa2f Mon Sep 17 00:00:00 2001 From: Phil Date: Sun, 7 May 2023 21:23:09 +0100 Subject: [PATCH] Added files to folder --- speedtest.csv | 1 + speedtest.sh | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 speedtest.csv create mode 100755 speedtest.sh diff --git a/speedtest.csv b/speedtest.csv new file mode 100644 index 0000000..657db49 --- /dev/null +++ b/speedtest.csv @@ -0,0 +1 @@ +Date,Miles to Server,Download,Upload diff --git a/speedtest.sh b/speedtest.sh new file mode 100755 index 0000000..849c810 --- /dev/null +++ b/speedtest.sh @@ -0,0 +1,34 @@ +#!/bin/bash + +# Set the path to the log file +LOG_FILE="/LINK/TO/File/speedtest.csv" + +# Run the speedtest and parse the output +SPEEDTEST=$(speedtest-cli --csv) + +# Check if the output is empty or contains errors +if [ -z "$SPEEDTEST" ] || [[ "$SPEEDTEST" == *"ERROR"* ]]; then + echo "Speedtest failed: $SPEEDTEST" + exit 1 +fi + +PING=$(echo "$SPEEDTEST" | awk -F',' '{print $6}') +DOWNLOAD=$(echo "$SPEEDTEST" | awk -F',' '{print $7}') +UPLOAD=$(echo "$SPEEDTEST" | awk -F',' '{print $8}') + +# Check if the required fields are missing or invalid +if [ -z "$PING" ] || [ -z "$DOWNLOAD" ] || [ -z "$UPLOAD" ]; then + echo "Missing or invalid speedtest fields: PING=$PING, DOWNLOAD=$DOWNLOAD, UPLOAD=$UPLOAD" + exit 1 +fi + +# Convert the download and upload speeds to Mbps +DOWNLOAD_Mbps=$(awk "BEGIN { printf \"%.1f\", $DOWNLOAD / (1024*1024) }") +UPLOAD_Mbps=$(awk "BEGIN { printf \"%.1f\", $UPLOAD / (1024*1024) }") + +# Append the result to the log file +echo "$(date +"%Y-%m-%d %H:%M:%S"),$PING,$DOWNLOAD_Mbps Mbps,$UPLOAD_Mbps Mbps" >> "$LOG_FILE" + +# Import the log file into Gnumeric to create a graph +# ssconvert "$LOG_FILE" /tmp/log.ods +