Skip to content

Instantly share code, notes, and snippets.

@svanoort
Last active July 3, 2022 01:56
Show Gist options
  • Save svanoort/675f9a3f05a29a9fb051f4dbfa1abecb to your computer and use it in GitHub Desktop.
Save svanoort/675f9a3f05a29a9fb051f4dbfa1abecb to your computer and use it in GitHub Desktop.
Do a bash speedtest and reboot router if under 5 MBit
#!/bin/bash
# Curl the bandwidth test site for 10 MB file and get speed in bytes/second, reboot cable modem if <5 MBit
# Useful as bash alias that retests and triggers every hour:
# alias continuously_speedtest='while [ true ]; do echo "Sleeping 1 hour and then speedtesting network"; sleep 3600; bash ~/speedtest-restart.sh; done'
set -o pipefail
echo 'Speedtesting modem now'
DOWN_SPEED=$(curl http://speedtest.wdc01.softlayer.com/downloads/test10.zip -t 100 -o /dev/null -s -w "%{speed_download}" | sed -E "s/\.[0-9]+//g")
if [ "$?" -ne 0 ]; then
echo "Speed test failed!"
exit 1
fi
if [ "$DOWN_SPEED" -lt 625000 ]; then #625 kB/s = 5 MBit
echo "Network connection too slow at $DOWN_SPEED, restarting modem and waiting a minute!!!"
curl -s -o /dev/null http://192.168.100.1/reset.htm?reset_modem=Restart+Cable+Modem
sleep 60
echo "Modem should be back, retesting speed"
DOWN_SPEED=$(curl http://speedtest.wdc01.softlayer.com/downloads/test10.zip -o /dev/null -s -w "%{speed_download}" | sed -E "s/\.[0-9]+//g")
echo "After reboot, speed is $DOWN_SPEED"
else
echo "Modem fast enough at $DOWN_SPEED B/s"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment