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)