The power button is pretty boring just turning the computer off.
Time to make it special for those headless Linux machines that play music but don’t have a keyboard.
Make sure ACPI is installed.
~$ sudo apt-get install acpi
Backup the old script.
~$ sudo cp /etc/acpi/powerbtn.sh /etc/acpi/powerbtn.sh.bak
Clear all of that nonsense out of the old script and start with a fresh slate.
~$ sudo cat > /etc/acpi/powerbtn.sh
Hit ctrl-c to finish
But that only lets you do one thing with your button!
Lets fix that with a little evil and trickery. The following will wait for repeated presses after the first for different results.
Replace /etc/acpi/powerbtn.sh with this.
Now create /root/mainpowerbutton.sh and place this in it.
echo “i’ve been touched” >> /root/scriptisrunning
if [ `cat /root/scriptisrunning | wc -l` -eq 1 ]; then
if [ `cat /root/scriptisrunning | wc -l` -eq 2 ]; then
if [ `cat /root/scriptisrunning | wc -l` -eq 3 ]; then
This allows you to press the button multiple times with different results for each press. The sleep timer will reset with each press so this can be expanded to any number of button presses. Just copy the if statement and change the -eq to the number of presses. Then put the path to the program or script you want to run on the next line. Make sure the if statement has a corresponding fi to end it.