A simple shell script for OpenWRT-based routers to turn all LEDs on or off on a schedule, e.g. to avoid light pollution at night.
This script was written for and tested on a Fritz!Box 7530/Fritz!Box 4040 running OpenWRT. It should work on other OpenWRT devices as well, but LED names and behaviour may differ. In particular, the line
echo default-on > /sys/class/leds/red:info/triggerreferences the red:info LED, which is specific to the Fritz!Box 7530. On other devices, this LED may not exist or may have a different name. Check your device's available LEDs with:
ls /sys/class/leds/You can safely remove or adjust that line if you don't need a status LED to remain on when the others are switched off.
leds.sh on # Restore normal LED behaviour by restarting the LED service
leds.sh off # Turn off all LEDs (except the red info LED on the Fritz!Box 7530)Place the script on your router (e.g. /root/leds.sh) and make it executable:
chmod +x /root/leds.shThen add a cron job via crontab -e, for example to turn the LEDs off at 23:55 and back on at 06:00:
55 23 * * * /root/leds.sh off
0 6 * * * /root/leds.sh on
on— Runs/etc/init.d/led restart, which restores the default LED triggers as configured by OpenWRT.off— Iterates over all entries in/sys/class/leds/and sets their trigger tonone, effectively turning them off. On thered:infoLED is then set todefault-onas a minimal status indicator.