Hi,
We have a rasp-pi that is running headlessly and when we want to check whats going on we connect to it with a laptop via VNC. However there are occasions when we want to be able to shut it down when we don't have a laptop present and therefore cant shut it down properly. Is it possible to shut it down by having a script that monitors the an I/O port and waits for a contact closure and then issues the command "sudo shutdown -h now". Will this work, say using a shell script or would python be better.
Cheers.
-
- Posts: 117
- Joined: Wed Jan 09, 2013 12:14 pm
Re: shutting down rasp pi via I/O port
Hello
I followed this >>>
http://www.raspberrypi.org/phpBB3/viewtopic.php?p=186137#p186137
worked for me
I followed this >>>
http://www.raspberrypi.org/phpBB3/viewtopic.php?p=186137#p186137
worked for me
Re: shutting down rasp pi via I/O port
I did this a slightly different way.
I have an old USB memory stick that is too small to be of much use. I created a udev rule (program that monitors devices and does stuff when they are connected/removed) that invokes a shutdown whenever that particular stick is inserted. Advantages are 1) No extra scripts need to be running, 2) No wiring to do.
Pretty much any USB device will do, as long as it has a unique serial number or device ID that can be detected.
as an example, my rule file is (/etc/udev/rules.d/99-shutdown.rules You'll need sudo, or to be root to create/edit this file)
The ENV{ID_FS_UUID} value is the unique ID of the filesystem on the first partition of the device.
The rule means: When any device known to the Linux KERNEL as /dev/sd(anything)1 is added to the system, and it has a UUID of bag-scary-long-code-number, RUN the command /sbin/shutdown -h now (halt)
I have an old USB memory stick that is too small to be of much use. I created a udev rule (program that monitors devices and does stuff when they are connected/removed) that invokes a shutdown whenever that particular stick is inserted. Advantages are 1) No extra scripts need to be running, 2) No wiring to do.

Pretty much any USB device will do, as long as it has a unique serial number or device ID that can be detected.
as an example, my rule file is (/etc/udev/rules.d/99-shutdown.rules You'll need sudo, or to be root to create/edit this file)
Code: Select all
# Shutdown system when specific memory stick is inserted
KERNEL=="sd*1",ACTION=="add",ENV{ID_FS_UUID}=="3c8dd6cc-0fef-4ad9-b58f-638f1e8491dc",RUN="/sbin/shutdown -h now"
The rule means: When any device known to the Linux KERNEL as /dev/sd(anything)1 is added to the system, and it has a UUID of bag-scary-long-code-number, RUN the command /sbin/shutdown -h now (halt)