Created
January 25, 2016 01:30
-
-
Save fangdingjun/5ad7578f7dcb93a13303 to your computer and use it in GitHub Desktop.
check network connectivity, re-dial when the network is down
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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