Skip to content

Instantly share code, notes, and snippets.

@fangdingjun
Created January 25, 2016 01:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fangdingjun/5ad7578f7dcb93a13303 to your computer and use it in GitHub Desktop.
Save fangdingjun/5ad7578f7dcb93a13303 to your computer and use it in GitHub Desktop.
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