Skip to content

Instantly share code, notes, and snippets.

@rlogiacco
Created January 6, 2016 00:25
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 rlogiacco/a7618fda3f7a60d94b2d to your computer and use it in GitHub Desktop.
Save rlogiacco/a7618fda3f7a60d94b2d to your computer and use it in GitHub Desktop.
PlusberryPi Power
#!/bin/bash
# monitor GPIO pin 21 for shutdown signal
# export GPIO pin 21 and set to input with pull-up
echo "21" > /sys/class/gpio/export
echo "in" > /sys/class/gpio/gpio21/direction
# wait for pin to go low
while [ true ]; do
if [ "$(cat /sys/class/gpio/gpio21/value)" == '0' ]; then
echo "Raspberry Pi Shutting Down!"
halt &
exit 0
fi
sleep 1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment