Programmatically determine default/active WAN in multi-WAN setup

Here's what I've come up with to get the job done. Runs every 5 minutes via cron.
#!/bin/sh

get active gateway and current time

CURRENT_TIME="$(date +"%T")" CURRENT_GW="$(netstat -rn | grep default | awk '{print $4}')"

if [ $CURRENT_GW = "em2" ]; then #check if WAN1 is up or not WAN1_STATUS="$(pfSsh.php playback gatewaystatus brief | grep WANGW | awk '{print $2}')" if [ $WAN1_STATUS = "none" ]; then #WAN1 is back online, stop/start WAN2 echo "$CURRENT_TIME: Bringing down em2" ifconfig em2 down echo "$CURRENT_TIME: Sleeping for 30s" sleep 30 echo "$CURRENT_TIME: Bringing up em2" ifconfig em2 up fi else echo "$CURRENT_TIME: Nothing to do!" fi

/r/PFSENSE Thread Parent