Skip to content

Instantly share code, notes, and snippets.

@jdbevan
Created November 23, 2015 10:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdbevan/e7af4711ce7854131aff to your computer and use it in GitHub Desktop.
Save jdbevan/e7af4711ce7854131aff to your computer and use it in GitHub Desktop.
Speedtest-cli wrapper
#!/bin/bash -u
WDIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
#timeout () {
# SLEEPTIME="$1"
# COMMAND="$2"
# ( cmdpid=$BASHPID; \
# (sleep "$SLEEPTIME"; kill $cmdpid) \
# & exec "$COMMAND" )
#}
while [ true ]
do
RESULTS=`speedtest-cli`
# RESULTS=( cmdpid=$BASHPID; (sleep 60; kill $cmdpid) & exec speedtest-cli )
if [ "$?" -eq "0" ]; then
PING=`echo "$RESULTS" | grep -o "[0-9]\+.[0-9]\+ ms" | grep -o "[0-9.]\+"`
DOWNLOAD=`echo "$RESULTS" | grep "^Download" | grep -o "[0-9.]\+"`
UPLOAD=`echo "$RESULTS" | grep "^Upload" | grep -o "[0-9.]\+"`
TIME=`date "+%Y-%m-%d %H:%M:%S"`
echo -e "$TIME\t$PING\t$DOWNLOAD\t$UPLOAD" >> "$WDIR/speedtest.log"
fi
sleep 300
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment