Run script after sleeping

I have this in /usr/lib/pm-utils/sleep.d/ but it does not execute when returning from the sleep state.

What am I doing wrong?

#!/bin/sh

case $1 in
    resume|thaw)
	   amixer -D pulse sset Master 60%
        cvlc --play-and-exit /usr/share/sounds/My_Sounds/Short_doorbell.wav
	;;
    suspend|hibernate)
	   
	;;
esac

You need to quote $1 as "$1" and are missing exit 0 at the very end of the script.

Also a good idea to provide PATH= so that the script can find amixer and cvlc.

See other examples in that dir.

1 Like

I made your changes, but no luck.

#!/bin/sh

PATH=/usr/bin/:/usr/share/sounds/

case "$1" in
    resume|thaw)
	   amixer -D pulse sset Master 60%
        cvlc --play-and-exit /usr/share/sounds/My_Sounds/Short_doorbell.wav
	;;
    suspend|hibernate)
	   
	;;
esac

exit 0

Here's what I did,

touch /tmp/fixit

cd /usr/lib/pm-utils/sleep.d/

created 80_fixit

#!/bin/sh

case "$1" in
	suspend|hibernate) 	echo "suspend" >> /tmp/fixit  	;;	
	resume|thaw)   		echo "resume" >> /tmp/fixt  	;;
esac

exit 0

sudo chmod +x 80_fixit

Command sudo pm_suspend ... the laptop went to suspend mode (power button is blinking).
Pushed the power button, laptop woke up. Looked at the file /tmp/fixit, it says
suspend
resume

You can also check /var/log/pm-suspend.log which logs the actions of every script that was in /usr/lib/pm-utils/sleep.d/ If I close the lid of my laptop, nothing happens since I have not defined this event as "suspend" -- probably I have it "do nothing"

I hope this helps.

I put scripts of my modem and mouse for running before and after sleep to this location

/lib/systemd/system-sleep/

Please do not forget to make the script executable.

I did as you posted. It make a 0 byte fixit file.
Now when I suspend my desktop computer, I use the sleep button. (Half moon on the key)

There are two ways to test suspend, 1) force suspend with sudo pm-suspend or 2) close the lid assuming in power options you have defined what to do when lid is closed.

touch /tmp/fixit will create a zero bytes file. Then, if you use method 1) it will append to that file. I tried method 2, my laptop did not write a /var/log/pm-suspend.log but it wrote in /var/log/syslog that system is suspending. I have to figure out why.

On systems that run systemd (instead of init), it is preferable to use /lib/systemd/system-sleep/ and scripts will be called with "pre" and "post" parameters. In my example, I just wanted to show you how to approach the problem. Two years ago, I wrote an article about it, https://www.azloco.org/2019/04/06/systemd-suspend-resume-script/

1 Like