LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware
User Name
Password
Slackware This Forum is for the discussion of Slackware Linux.

Notices


Reply
  Search this Thread
Old 05-13-2022, 12:25 PM   #1
KarlF
LQ Newbie
 
Registered: Jul 2019
Posts: 15

Rep: Reputation: Disabled
How to execute a scrip upon waking up from s3 sleep?


Hi!

Does anyone know how to execute a script/program immediately after the computer wakes up from sleep with slackware?

Thanks.

Karl
 
Old 05-13-2022, 12:46 PM   #2
giomat
Member
 
Registered: Jul 2017
Posts: 342

Rep: Reputation: 243Reputation: 243Reputation: 243
You should have a look into elogind hook scripts.
https://wiki.gentoo.org/wiki/Elogind...ming.2Fthawing
You can setup scripts to be executed pre and post suspend/hibernation
 
1 members found this post helpful.
Old 05-13-2022, 12:47 PM   #3
0XBF
Member
 
Registered: Nov 2018
Distribution: Slackware
Posts: 806

Rep: Reputation: 938Reputation: 938Reputation: 938Reputation: 938Reputation: 938Reputation: 938Reputation: 938Reputation: 938
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

Last edited by 0XBF; 05-13-2022 at 12:51 PM.
 
1 members found this post helpful.
Old 05-13-2022, 01:09 PM   #4
teckk
LQ Guru
 
Registered: Oct 2004
Distribution: Arch
Posts: 5,159
Blog Entries: 6

Rep: Reputation: 1836Reputation: 1836Reputation: 1836Reputation: 1836Reputation: 1836Reputation: 1836Reputation: 1836Reputation: 1836Reputation: 1836Reputation: 1836Reputation: 1836
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.
 
1 members found this post helpful.
Old 05-13-2022, 01:26 PM   #5
KarlF
LQ Newbie
 
Registered: Jul 2019
Posts: 15

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by 0XBF View Post
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.

Thanks again!

Karl
 
  


Reply

Tags
execute, sleep



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Disable login screen (auto login) after waking from sleep (KDE/KDM) damgar Slackware 2 08-18-2018 10:29 PM
WPA authentication fails after waking from sleep vs. dLink (Ubuntu 10.04) dewdrop_world Linux - Wireless Networking 3 05-12-2011 04:54 PM
Waking from S3 sleep doesn't turn the screen on (Asus A6U) MasterOfTheWind Linux - Laptop and Netbook 2 05-03-2011 02:06 AM
(server name) zmd: ShutdownManager (WARN): Going to sleep, waking up at (time) bigknuckles SUSE / openSUSE 0 01-25-2008 03:37 PM
Waking my computer up after it goes to sleep Fosforo Ubuntu 4 01-20-2007 02:35 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Distributions > Slackware

All times are GMT -5. The time now is 06:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration