Last active
November 26, 2022 11:23
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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