Correct way to execute a script on resume from suspend
First, Ubuntu 20.04 uses systemd, not pm. Second, the script content with systemd is different. You should try with this template below and put your script in /lib/systemd/system-sleep/
with executable bit:
#!/bin/sh
PATH=/sbin:/usr/sbin:/bin:/usr/bin
case "$1" in
pre)
#code execution BEFORE sleeping/hibernating/suspending
;;
post)
#code execution AFTER resuming
;;
esac
exit 0
The line where PATH=/sbin:/usr/sbin:/bin:/usr/bin
is assigned explicitely is required if you intend to call commands as you would do in terminal command-line. If not, you must use absolute path of the related command binary file e.g. $ /usr/bin/touch /myfile
instead of $ touch /myfile
.
Find absolute path of a command binary file
You can get/check absolute path of a specific command binary file with e.g. $ whereis touch
, which will output the absolute path of the binary /usr/bin/touch
which interests us :
$ whereis touch
touch: /usr/bin/touch /usr/share/man/man1/touch.1.gz
Is systemd suspend.target enabled?
In case it doesn't work, you may check if systemd related targets are enabled with
$ sudo systemctl status sleep.target suspend.target hibernate.target hybrid-sleep.target
The output should look like :
● sleep.target - Sleep
Loaded: loaded (/lib/systemd/system/sleep.target; static; vendor preset: enabled)
Active: inactive (dead)
Docs: man:systemd.special(7)
[...]
● suspend.target - Suspend
Loaded: loaded (/lib/systemd/system/suspend.target; static; vendor preset: enabled)
Active: inactive (dead)
Docs: man:systemd.special(7)
[...]
● hibernate.target - Hibernate
Loaded: loaded (/lib/systemd/system/hibernate.target; static; vendor preset: enabled)
Active: inactive (dead)
Docs: man:systemd.special(7)
[...]
● hybrid-sleep.target - Hybrid Suspend+Hibernate
Loaded: loaded (/lib/systemd/system/hybrid-sleep.target; static; vendor preset: enabled)
Active: inactive (dead)
Docs: man:systemd.special(7)