Can I run a script only when a wan interface gets a IP?

This is originally what I'm using. I don't know if the service part is written up to par. I did have a hotplug script starting the ping script but I could be using one of 3 wans. I could just put all 3 wan interfaces in the hot plug but I wanted to try something a little more "universal". Maybe with the logic of:
if $ACTION = ifup; then
get list a 'wans' from firewall config (uci get firewall.cfg03dc81.network)
if $INTERFACE = ANY of those in the list of wans; then
check is service is running, if not start service.

for the ifdown part it would be the same except check if ALL wan interfaces in the list are down, and if they are, then stop the script. I just don't know how to parse the list of wans and check their state.

/etc/init.d/ledpingchecksvc

#!/bin/sh /etc/rc.common

START=21
STOP=89
USE_PROCD=1

start_service() {
logger -t custom.script.ledpingchecksvc "Starting web ping check for INTERNET LED"
procd_open_instance
procd_set_param command "/usr/sbin/ledpingchecksvc"
procd_set_param stdout 0
procd_set_param stderr 0
procd_set_param respawn
procd_close_instance
}
service_triggers()
{
procd_add_reload_trigger "network"
}
reload_service() {
logger -t custom.script.ledpingchecksvc "Restarting web ping check for INTERNET LED"
echo 0 > /sys/class/leds/y1:blue:internet/brightness #turn off LED
}
stop_service() {
logger -t custom.script.ledpingchecksvc "Stopping web ping check for INTERNET LED"
echo 0 > /sys/class/leds/y1:blue:internet/brightness #turn off LED
}

usr/sbin/ledpingcheck

#!/bin/sh

while :
do
ping -q -w 5 -c 1 8.8.8.8
if [ "$?" -eq 0 ]; then
  echo 1 > /sys/class/leds/y1:blue:internet/brightness #turn on LED
else                                              
  echo 0 > /sys/class/leds/y1:blue:internet/brightness #turn off LED
fi
sleep 10
done