Last active
June 22, 2018 20:46
-
-
Save spthm/7f3c3a7b96c45fce3a49022cbd1cf9d9 to your computer and use it in GitHub Desktop.
Turn on/off Raspberry Pi 2 Model B POWER LED
This file contains hidden or 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
#!/bin/bash | |
if [[ $# -eq 0 || "$1" == "-h" || "$1" == "--help" ]]; then | |
echo "Usage: led_ctl [on|off|auto]" | |
echo "on -- turn POWER LED on" | |
echo "off -- turn POWER LED off" | |
echo "auto -- turn POWER LED on if between 08:00 and 20:00, else turn off" | |
echo "Run as root." | |
exit 0 | |
fi | |
if [[ $EUID -ne 0 ]]; then | |
echo "ERROR: Must run as root" | |
exit 1 | |
fi | |
function turn_pwr_led_off { | |
echo 0 > /sys/class/leds/led1/brightness | |
} | |
function turn_pwr_led_on { | |
echo 1 > /sys/class/leds/led1/brightness | |
} | |
if [[ "$1" == "off" ]]; then | |
turn_pwr_led_off | |
fi | |
if [[ "$1" == "on" ]]; then | |
turn_pwr_led_on | |
fi | |
if [[ "$1" == "auto" ]]; then | |
now=$(date +"%H%M") | |
if [[ 800 -le $now && 2000 -ge $now ]]; then | |
turn_pwr_led_on | |
else | |
turn_pwr_led_off | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put in
/usr/local/bin
(or anywhere that is on yourPATH
), and make sure it has the right owner and permissions,The
staff
group is a Debian/Raspbian/Ubuntu/etc. thing; you probably wantroot:root
if you're on a distro which isn't a Debian derivative.