Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
check network connectivity, re-dial when the network is down
#!/bin/bash
# speed check url
url="https://httpbin.org/bytes/10240"
let i=0
timeout=3
while true
do
#ping -c 1 114.114.114.114 >/dev/null 2>&1
curl $url --connect-timeout $timeout --speed-limit $((10*1024)) --speed-time 5 -o /dev/null -s -S
if [ $? -ne 0 ];then
let i=i+1
else
let i=0
fi
if [ $i -ge 3 ];then
echo $(date) "re-dialing..."
sudo poff dsl-provider >/dev/null 2>&1
sleep 5
sudo pon dsl-provider >/dev/null 2>&1
let i=0
fi
hour=$(date "+%H")
if [ $hour -ge 19 -a $hour -le 23 ];then
sleep 5
else
sleep 60
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.