1
When I push the power button, I want to run a script. For the sake of this scenario, say file.sh. So when I push the power button, I want to run file.sh and only file.sh.
Most of the solutions I found involved editing /etc/acpi/powerbtn.sh
, but that file does not exist on my system. (I'm running Ubuntu 19.04) I tried creating it and populating it with the standard contents, but it didn't work. I also tried listening for key presses with acpi_listen
, but nothing happened when I pushed keys, so I don't know if I just did it wrong or what. I tried using xev
,which did pick up key events but nothing registered when I hit the power button.
Anyone know how to accomplish this, or what I am doing wrong?
P.S. I should mention, I would prefer a solution that can be done on the command line, ideally one without any 3rd party software. Thanks.
Similar question, but with no solutions:
https://askubuntu.com/questions/473693/run-a-script-when-power-button-is-pushed
Basically looking for the Linux equivalent of what they did here:
https://stackoverflow.com/questions/12434863/executing-a-batch-script-on-windows-shutdown
EDIT: this is what I get from syslog:
Feb 9 13:01:01 joe-Aspire-E5-576G gnome-session-binary[1624]: Entering running state
And this is my file in events:
event=button/power
action=/home/jeremiahgage/Desktop/test/sc.sh
`
I have tried this solution previously but it does not work. I get no feedback in syslog when pressing the power button on my machine. – ragnvaldr.js – 2020-02-09T17:59:22.617
I just edited the original post with the output from the terminal when I followed your solution. – ragnvaldr.js – 2020-02-09T18:04:13.020
Ok, so I got feadback working, but it wont run my script, this is my file:
event=button/power action=/home/jeremiahgage/Desktop/test/sc.sh
– ragnvaldr.js – 2020-02-09T18:58:26.370(1) Check that
acpid
is running withpidof acpid
. (2) Does your script logs something to a file? I had userlogger
command as an easy way to log something somewhere (syslog
). But, you can write something to a file in/tmp
for example... – FedonKadifeli – 2020-02-10T09:20:54.397