Skip to content

Instantly share code, notes, and snippets.

@AzimsTech
Last active November 26, 2022 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AzimsTech/8067205a08060539d2f7090c271ffb9f to your computer and use it in GitHub Desktop.
Save AzimsTech/8067205a08060539d2f7090c271ffb9f to your computer and use it in GitHub Desktop.
Openwrt: D-Link DIR-842 C2 - Switch on a led when internet connection is available
# Switch on a led when internet connection is available
#!/bin/bash
#
while :
do
ping -c5 -q 8.8.8.8
status=$?;
case $status in
0)
echo "host is alive";
;;
1)
echo "network unreachable or host not responding to pings";
;;
2)
echo "No route to host or other error";
;;
esac
if [ $status -eq 0 ]; then
/bin/echo "Internet is up"
/bin/echo "1" > /sys/class/leds/green:wps/brightness # wps led on
else
/bin/echo "Internet is down"
/bin/echo "0" > /sys/class/leds/green:wps/brightness # wps led off
fi
sleep 30
done
# give the right permission
# chmod 755 /root/internet-check.sh
# to launch the script at the startup, put the following line right before the "exit 0" line in the "/etc/rc.local" file
# /bin/sh /root/internet-check.sh &
# source: https://forum.openwrt.org/t/how-to-switch-on-a-led-when-internet-connection-is-available/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment