Run a command as su after every wake from suspend

Ubuntu 18.04 wakes immediately from suspend, and will revert this setting back after running echo XHC > /proc/acpi/wakeup.

  • So how can I run this command every time my ThinkPad wakes from suspend?

EDIT:

I've added the following wakeup.sh to be run as a systemd

#!/bin/bash
echo XHC > /proc/acpi/wakeup

and used the service template found here: Execute a network script at wake-up with systemd (15.04)

the service is running but after 1 suspend XHC is enabled again.. is it not being run as sudo? how is this a thing in ubuntu? i just want my thinkpad to stay suspended.


Solution 1:

since this is posted no where on the internet, i hope this helps someone else

to run a command as su after wakeup create whatever.service in etc/systemd/system

[Unit]
Description=Run user script after suspend
After=basic.target suspend.target hibernate.target

[Service]
User=root
Environment=DISPLAY=:0
ExecStart=/home/you/whatever.sh

[Install]
WantedBy=basic.target suspend.target hibernate.target

then in home/you/whatever.sh

#!/bin/bash

your command here

then

sudo chmod +x /home/you/whatever.sh

then run

systemctl daemon-reload

and

sudo systemctl enable whatever.service