After lots of fiddling I was able to create and fine-tune a code to do the following:
White LED when Internet is Connected
Amber LED when Internet is Disconnected
LED is off when WAN Ethernet cable is unplugged
These checks are are made every 10 seconds
#!/bin/sh /etc/rc.common
IP='8.8.8.8'
while true
do
wan_status=$(swconfig dev switch0 port 4 get link | sed -r 's/.*link:([[:alnum:]]*).*/\1/')
if [ "$wan_status" == "down" ]
then
echo 0 > /sys/class/leds/pca963x:shelby:white:wan/brightness
echo 0 > /sys/class/leds/pca963x:shelby:amber:wan/brightness
else
fping -c1 -t300 $IP 2>/dev/null 1>/dev/null
if [ "$?" = 0 ]
then
echo "Host found"
echo 255 > /sys/class/leds/pca963x:shelby:white:wan/brightness
echo 0 > /sys/class/leds/pca963x:shelby:amber:wan/brightness
else
echo "Host not found"
echo 255 > /sys/class/leds/pca963x:shelby:amber:wan/brightness
echo 0 > /sys/class/leds/pca963x:shelby:white:wan/brightness
fi
fi
sleep 10
done
exit 0
However, I lost the basic functionally of the blinking led according to the TX/RX activity.
I thought about making the script an init.d script however, it will be only executed one and using the while loop yield the same results as above.
I also thought about using crontab but its granularity is 60 seconds. Way too much time.
Can someone shed any light to do this while keeping the above added functions operating? @jeff
I am not experienced with Bash Scripting, so I will take your edit into consideration to clean the script.
Yes. I am using fping tool instead of the default ping. It is much faster If I need more pings, I can ping subnet hosts in a more convenient way rather than determining the Host ip. Also, I can test if particular TCP ports per host are up and can also check if a host alive/up instead of checking for "0" response from an icmp request, but I haven't used it