Posts: 20
Joined: Tue Aug 14, 2012 4:17 am

shutting down rasp pi via I/O port

Tue Jan 29, 2013 2:17 am

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.


Posts: 117
Joined: Wed Jan 09, 2013 12:14 pm

Re: shutting down rasp pi via I/O port

Tue Jan 29, 2013 5:31 am


I followed this >>>


worked for me

User avatar
Posts: 17975
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: shutting down rasp pi via I/O port

Tue Jan 29, 2013 7:15 am

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)

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 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)

Return to “Beginners”