7

I've been looking for solutions to have my computer go to sleep at 1am EST and wakeup at 6pm EST every day. Thus far I've been unsuccessful.

I tried using rtcwake and cronjobs as well as the script here:

Automatically Resume from Sleep / Standby / Suspend | Ubuntu Forums

Even other forums I couldn't make it work.

Would really appreciate help.

P.s. I have disk encryption enabled so I can't hybernate.

Ryan
  • 231
  • 1
  • 2
  • 8

3 Answers3

10

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

An0n
  • 2,049
  • 1
  • 11
  • 27
  • Thank An0n. I'm not sure why but that application doesn't seem to be working see configuration: http://prntscr.com/ijm11d At 1:37pm EST I configured it as seen in that image. Hit "Save" and then "Quit". It's now 2:09 EST and nothing. Any ideas? – Ryan Feb 25 '18 at 19:08
  • It uses UTC time. – An0n Feb 25 '18 at 19:10
  • it went to sleep on time but failed to wake up. I had this same problem when I used rtcwake and cronjobs together. – Ryan Feb 26 '18 at 15:46
  • You must change that in your bios settings in the power settings should be something like "Auto-power-on" – An0n Feb 26 '18 at 15:49
  • Please mark the Answer as Accepted if it solved your issue. So people know the question is answered. Thx in advance. – An0n Feb 26 '18 at 15:58
  • No luck with the power settings in my bios. I'm using an Z370 Aorus Gaming 5 chipset. I tested out 3 different features. Also tried switching to RTC wake but that wouldn't even put my computer to sleep, specifically : sudo rtcwake -m no -l -t "$(date -d 'today 16:00:00' '+%s')". I tested the time with UTC and EST and gave the system 10 minutes to to detect the new cronjob. – Ryan Feb 28 '18 at 15:50
  • I got a write error when I used it with "-m disk" (I think this is hybrid sleep) but it worked with "-m mem" (suspend to RAM). – adazem009 Jun 03 '20 at 16:44
4

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.
WinEunuuchs2Unix
  • 99,709
  • 34
  • 237
  • 401
0

I wanted my computer to sleep at 11:59pm local time each night and wake up each morning at 9:00am.

And I know that cronjobs can help with this.

I used a tool (such as https://cron.help/#59_23_*_*_*) to show me that the correct syntax for the go-to-sleep schedule that I want is 59 23 * * *.

And then I needed to calculate how many seconds the sleep should last: 9:00am is 9 hours + 1 minute after 11:59pm. (9 * 60 + 1) * 60 = 32460 seconds

So I ran crontab -e to edit the cron jobs via vim and added these 2 lines:

# inspired by https://askubuntu.com/a/1348204/48214 and https://askubuntu.com/a/1012051/48214 and https://itectec.com/ubuntu/ubuntu-automatically-sleep-and-wake-up-at-specific-times/
59 23 * * * /usr/sbin/rtcwake -m disk -s 32460 >> /code/cron.log 2>&1

And I saved the file.


The steps above will work for most people on most computers, but unfortunately I realized from this quick test that my particular ancient computer has problems with rtcwake.

So instead, what I'm using now only suspends my computer on a schedule, and I haven't figured out how to schedule waking up yet:

59 23 * * * echo "$(date) Running /usr/local/bin/systemctl-suspend" >> /code/cron.log && /usr/local/bin/systemctl-suspend >> /code/cron.log 2>&1

which I got from https://unix.stackexchange.com/a/642533/48973.

Ryan
  • 249
  • 1
  • 4
  • 23