WAN test script - quick and dirty

My setup is slightly different to yours maybe - but here goes

Internet -> Billion 8800NL -> Linksys WRT3200 ACM

The Linksys is running Lede

Billion is in Bridge mode - Linksys does the connection (I have this so my Linksys can stay as my main router even if I change my modem)

On the HA Server I have 3 scrips - A master script and one for each device

And a crontab that runs hourly

0 * * * * /home/user/scripts/restart_inet_connection.sh >> /home/user/scripts/inet.log 2>&1

Main Script

#!/bin/bash
fping -u google.co.uk >& /dev/null
if [ $? -ne 0 ]; then
        echo "Date: $(date)"
        echo "$(date): Google.co.uk is not responding!! Attempting to repair internet connection."
        echo "$(date): Restarting Billion 8800NL"
        /home/user/scripts/restart_billion.sh 192.168.0.254 username password
        sleep 10s
        while ! fping -q 192.168.0.254 ; do echo "Billion has not rebooted yet"; sleep 10s ; done
        echo "$(date): Billion is online. Waiting 1 minute for ADSL to sync"
        sleep 1m
        echo "$(date): Restarting Linksys 3200"
        /home/user/scripts/router_reboot.sh 192.168.0.1
        sleep 10s
        while ! fping -q 192.168.0.1 ; do echo "Router has not rebooted yet"; sleep 10s ; done
#       while ! fping -q google.co.uk ; do echo "Internet is not responding yet"; sleep 10s ; done
        echo "$(date): Google.co.uk is now responding - Internet is now active again."
else
        echo "$(date): Google.co.uk is responding - Internet is active."
fi

On the Billion its running Telnet

Billion Script

#!/usr/bin/expect
#If it all goes pear shaped the script will timeout after 20 seconds.
set timeout 20
#First argument is assigned to the variable name
set name [lindex $argv 0]
#Second argument is assigned to the variable user
set user [lindex $argv 1]
#Third argument is assigned to the variable password
set password [lindex $argv 2]
#This spawns the telnet program and connects it to the variable name
spawn telnet $name
#The script expects login
expect "Login:"
#The script sends the user variable
send "$user\r"
#The script expects Password
expect "Password:"
#The script sends the password variable
send "$password\r"
#This hands control of the keyboard over two you (Nice expect feature!)
#interact
#Reboot
expect "> "
# Change the following value to whatever your devices reboot command is.
send "reboot\r"
interact

On the Linksys running LEDE I have a SSH pre-shared key with the HA server - LEDE is just Unix

Linksys 3200

#!/bin/bash

if [ "$#" -ne 1 ]; then
    echo "Illegal number of parameters";
    echo "Usage: $0 ROUTER_IP";
    exit;
fi


RouterToCheck=$1;

command="ssh root@${RouterToCheck} \"ifdown wan; sleep 5; ifup wan\""

result=`eval ${command}`

It’s all a bit convoluted but it checks is the WAN is up and reboots the right devices in the right order. Feel free to change for your devices (I had it working on a different device before I got the Billion and the Linksys)