#!/bin/bash

while true
do

wan_up=`ifstatus wan | awk '/"up":/ { print $2 }'`
wan_status=`mii-tool eth1`

if [ -z "${wan_status##*no link*}" ] && [ "$wan_up" = "true," ];
then
	echo "WAN going down, no cable connected"
	ifdown wan
	
elif [ -z "${wan_status##*ok*}" ] && [ "$wan_up" = "false," ];
then
	echo "WAN coming up, cable connected"
	ifup wan
	
fi

sleep 5
done

