-
-
Save ntrepid8/d6f0fafa57a42ca1b515c19e71492309 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash | |
LOG_PATH="/home/$(whoami)/log/speedtest.log" | |
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}" | |
else | |
printf "[$(date)] error\n" >> "${LOG_PATH}" | |
exit 1 | |
fi | |
exit 0 |
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>
.
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.
Came in handy after changing /usr/bin/speedtest
to /usr/bin/speedtest-cli
. Thanks!
Thank you. Works like a charm.
I had to manually put my home folder on LOG_PATH, for some reason the
Thanks again!.
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'