How to suspend after idle or inactivity period without desktop environment or X?
xautolock says it's for x-windows--so that's out. Pm-utils will do the shutdown, but damned if I can find a way to set an inactivity timer with it. How is this done? There must be a way...
|
First you need to define what kinds of activity should force the system to keep running. Keystrokes? Commands running in the foreground? Commands running in the background? Commands running via cron?
Next, you need to write a script to detect those activities, determine when the desired period of inactivity has elapsed, and then execute the pm-suspend or pm-hibernate command. |
Defining the events that keep the system running is one thing, but what process is running the timer in the first place and ready to sleep if those events don't happen? You mention a script, but is that an efficient and reliable (i.e. elegant) method? Assuming that is the suggestion, how would I run this--rc2.d?
I'm rather surprised that there isn't some apt-get solution out there that just "does" this with a little bit of input on the thresholds and such. |
|
Quote:
Yes I can wax philosophical about what "stop using" means, but I don't want to. Just like windows or mac or Ubuntu, if I walk away and there aren't certain user applications running, they stop running and go night-night. I'm really confused as to why this is a seemingly exotic topic. I'm not being cranky, I'm just genuinely confused about it. |
Quote:
I was thinking about your question because I recently wrote a bash script to analyze the output of ck-list-sessions in order to determine whether any X session is active, and suspend the system after 5 minutes of inactivity, or 90 minutes if lsusb shows that a printer (which is shared) is attached and powered up. For your question, I had to use the w command. Here is a script which I shall call suspend_after_idle: Code:
#!/bin/bash Code:
* * * * * /path_to/suspend_after_idle 5 > /dev/null 2>&1 The line that extracts the idle time works as follows: Code:
w -sh | tr -s ' ' | cut -d ' ' -f 4 # cut the idle time column from the output of w Minor bugs: The script will not suspend the system if any of the following are true:
There may be other bugs or "unintended features." |
You can try sspender https://github.com/mountassir/sspender
It allows you to suspend your machine based on pre-defined CPU/Disk usage, and makes sure the machine wakes up at certain times when you need it to be ON. |
Generally waking up old, sleeping threads is frowned upon - but seems appropriate in this case ... :p
Looks interesting, and may help others in future via google. I'll see if I can organise a test on Fedora for you. |
All times are GMT -5. The time now is 07:34 AM. |