Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Script to run speedtest-cli via cron and log the results
#!/usr/bin/env bash
if result=$(/usr/bin/speedtest --simple); then
parsed_result=$(printf "${result}\"" | sed ':a;N;$!ba;s/\n/" /g' | sed 's/: /="/g')
printf "[$(date)] ${parsed_result}\n" >> "${LOG_PATH}"
printf "[$(date)] error\n" >> "${LOG_PATH}"
exit 1
exit 0
Copy link

ntrepid8 commented Jun 28, 2017

The log lines look like this:

[Wed Jun 28 02:11:32 UTC 2017] Ping="6.835 ms" Download="764.91 Mbit/s" Upload="244.43 Mbit/s"

Copy link

ntrepid8 commented Jun 28, 2017

The cron entry to run each hour at 5 minutes after looks like this:

# speedtest log
5 * * * * /path/to/script/cron_speedtest

Copy link

aausek commented Sep 30, 2018

Hi there. I'm very new to cron jobs but also eager to learn. I've tried to edit the syntax of the cron job itself without success. Would you be able to help me with this matter?
Right now this is what I have "* * * * * ~/Desktop/MAIN/code/" however keep getting the error "No such file or directory".

Thank you.

Copy link

lpil commented Oct 18, 2018

@aausek You will need to provide an absolute path, rather than one that uses the ~ home shortcut.

Copy link

qtronixx commented Nov 27, 2019

Hi there.
when i run the script, I have such an error.

sed: 1: ":a;N;$!ba;s/\n/" /g": unused label 'a;N;$!ba;s/\n/" /g'

Copy link

KaloyanP commented Jan 24, 2020

If your script doesn't run and your logs (get them with sudo grep CRON /var/log/syslog contain:

(CRON) info (No MTA installed, discarding output)

You might have to change the permissions on the script to be executable with chmod +x <name of script>.

Copy link

toddaitkins commented Feb 23, 2020

I got the script to work but I don't think the sed is working. I can't decipher it and not sure its intent but when I run the command without the two sed redirects it gives the same output either way. The output is dispersed across three lines instead of a nice neat one line log entry.

Copy link

Anthonycom commented Feb 12, 2022

Thanks. Edited line 3 and 5. Working like a charm

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