7

I'm trying to run a script once I push the power button instead of having my machine turn off. I'm running Ubuntu Server 13.04, but any answers also need to work on Server 14.04.

I've looked at ACPI events and such, tried editing the /etc/acpi/powerbtn.sh and /etc/acpi/events/powerbtn files but no luck anywhere.

So then I after reading this page https://wiki.archlinux.org/index.php/acpid, I ran sudo journalctl -f as instructed, but that didn't work. So I tried sudo acpi_listen and I got into the ACPI event listener. However, even from in there, pushing the power button gave me no output at all.

Is there another service in place which catches the power button events before ACPI? What files would I then need to edit to execute my script when the power button is pushed?

I've also tried sudo xev and that gave me no output on the power button either.

EDIT: I also have a Ubuntu Desktop system and on that system I can get output from ACPI and I can edit the /etc/acpi scripts. Is there something installed with Unity that miraculously enables ACPI?

EDIT AGAIN: Ended up doing a fresh install...ACPI worked. I guess I messed something up when I was experimenting and first tried to find a solution to this problem. What I did was place my python script in /etc/acpi/ and then added the following two lines to the top of /etc/acpi/powerbtn.sh

sudo python my_python_script.py
exit 0

And it worked. Thanks guys.

1

How about just placing your script in run level 6 as mentioned and detailed here:

How to run a command before the machine automatically shutdowns?

| improve this answer | |
  • Interesting idea, I'd prefer to intercept a system service...is there anything besides ACPI in Ubuntu 13.04 that would be eating the power button pressed event? – zaxvo Jul 14 '14 at 15:01
1

Place your python script in /etc/acpi/ and then add the following two lines to the top of /etc/acpi/powerbtn.sh

sudo python your_python_script.py
exit 0
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.