Check network and auto redial

#!/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

Source: https://gist.github.com/fangdingjun/5ad7578f7dcb93a13303

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.