How to execute a scrip upon waking up from s3 sleep?
SlackwareThis Forum is for the discussion of Slackware Linux.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
You can use elogind to handle that. Here's a quote from the loginctl man page:
Code:
[/usr]/lib[64]/elogind/system-sleep/, /etc/elogind/system-sleep/
Immediately before entering system suspend and/or hibernation elogind will run all executables in [/usr]/lib[64]/elogind/system-sleep/ and /etc/elogind/system-sleep/ and pass two arguments to
them. The first argument will be "pre", the second either "suspend", "hibernate", "hybrid-sleep", or "suspend-then-hibernate", depending on the chosen action. Immediately after leaving system
suspend and/or hibernation the same executables are run, but the first argument is now "post". All executables in this directory are executed sequentially, and execution of the action is not
continued until all executables have finished.
So you could make a script that resides in /lib64/elogind/system-sleep/ and detect when "$1" = "post" to hook a script after resuming from sleep.
Edit: Looks like I was a minute too slow, but I'll leave my reply up
You can also put the machine to sleep with rtcwake, wake it when you want, do something, go back to sleep. Good for an overnight tv show record.
Example:
Code:
#!/usr/bin/bash
#change dir
cd $HOME/some/where
#Set wake date/time here, sleep
rtcwake -m mem --date "2022-05-14 18:55:00
#Do something here
echo "Hello world"
sleep 10
#Return to sleep
systemctl suspend
Slack doesn't use systemd so, use what Slack uses.
You can use elogind to handle that. Here's a quote from the loginctl man page:
Code:
[/usr]/lib[64]/elogind/system-sleep/, /etc/elogind/system-sleep/
Immediately before entering system suspend and/or hibernation elogind will run all executables in [/usr]/lib[64]/elogind/system-sleep/ and /etc/elogind/system-sleep/ and pass two arguments to
them. The first argument will be "pre", the second either "suspend", "hibernate", "hybrid-sleep", or "suspend-then-hibernate", depending on the chosen action. Immediately after leaving system
suspend and/or hibernation the same executables are run, but the first argument is now "post". All executables in this directory are executed sequentially, and execution of the action is not
continued until all executables have finished.
So you could make a script that resides in /lib64/elogind/system-sleep/ and detect when "$1" = "post" to hook a script after resuming from sleep.
Edit: Looks like I was a minute too slow, but I'll leave my reply up
Thank you all for replying. This is exactly what I was looking for!
The reason was that I noticed that after waking up, I needed to execute hdparm -S 60 /dev/sd[bcd] on my raid array again, otherwise the disks would not spin down.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.