Tag Archives: rtcwake

Scheduling Linux laptop to suspend and re-animate at scheduled time.


I recently created an automate script which search the internet for certain items and email me the search results. It’s currently running on HP Probook and I don’t want to leave the laptop running indefinitely.

So, I created a cron job to run this script to automatically suspend the laptop when there are no interactive user using the system. The script use rtcwake command to suspend the system in memory and it seemed to work pretty nicely.

To use this script, login as root and saving the following to a file /root/scripts/hybernate

#!/bin/bash
SLEEP_DURATION=1800
if [ $# -gt 0 ]; then
SLEEP_DURATION=$1
fi

# Put the laptop to sleep, if no interactive login and wake up later
if [ `who | wc -l` -eq 0 ]; then
/usr/sbin/rtcwake -m mem -s $SLEEP_DURATION
fi

Change the script permissions:

chmod 755 /root/scripts/hybernate

Then add the following line to root crontabs:

# m h dom mon dow command
* * * * * /root/scripts/hybernate 1800 2>/dev/null

Advertisement