Sleep & Wakeup Schedule | Ubuntu 16.04.3 LTS

From terminal :

Suspend and wake up after 60 sec :

sudo rtcwake -m disk -s 60

Suspend and wake up today 16.00

sudo rtcwake -m no -l -t "$(date -d 'today 16:00:00' '+%s')"

Suspend and wake up tommorow 10.00 :

sudo rtcwake -m no -l -t $(date +%s -d 'tomorrow 10:00')

Suspend and wake up specific date and time :

sudo rtcwake -m no -l -t "$(date -d '2017-04-25 16:00:00' '+%s')"

To shutdown for Maintenance use :

sudo shutdown -P +60 "The system is going DOWN to maintenance mode in 60 minutes!"

sudo shutdown -P 22:10 "The system is going DOWN to maintenance mode at 22:10!"

Using Autopoweroff :

Download Autopoweroff:

wget https://github.com/deragon/autopoweroff/releases/download/3.0.0/autopoweroff-3.0.0-1.noarch.deb

Install Autopoweroff:

sudo dpkg -i autopoweroff-3.0.0-1.noarch.deb
sudo apt-get install -f

autopoweroff autopoweroff2


The script you are following is overly complicated. A simpler method is described here.

Before a full implementation of 1am sleep and 6am wake, you can do a simple 10 second test:

sudo rtcwake -m mem -s 10 && firefox

This test will ensure suspending to RAM actually works. Upon resuming firefox is automatically started up.

Rather than messing around with UTC, have your rtcwake command called from cron at 1am and wake up 18000 seconds later. Your cron table entry would look something like this:

0 1 * * *  sh /usr/sbin/rtcwake -m mem -s 18000 >> /home/Me/SuspendResume.log 2>&1

There is no need for sudo prefix because cron runs with sudo privileges.

Replace Me with your user name. Check the file SuspendResume.log for cron messages periodically and whenever there is a problem. 2>&1 option redirects error messages to the .log file.

Caveats

  • RTC stands for real-time clock. rtcwake uses your computer’s hardware clock, which you can set in your BIOS, to determine when your computer will wake up. If you’re using an old computer with a dying CMOS battery that can’t keep the clock running properly, this won’t work.
  • If sleep, suspend to RAM, or hibernate don’t work properly with your Linux system – perhaps because Linux doesn’t have the drivers to make them work properly with your hardware – this may not work.
  • Be careful when setting a laptop to automatically wake at a specific time. You wouldn’t want it waking up, running, and overheating or running down its battery in a laptop bag.