9

I basically want to have my PC sleep and also wake up at a specified time all the time forever. With research, I did find out about rtcwake but as far as I know it's basically a one time use that I would have to manually do everyday. I'm just looking for something that works automatically, and I just do not know how I can use bash to force the rtcwake command if that makes any sense at all.

In addition to wanting automatic sleep, I also have this issue of rtcwake not working anyway when using the "disk" option, as it throws the error:

 rtcwake: unrecognised suspend state 'disk'
2
  • 1
    I don't think, that waking a computer from a software inside a hard disk is possible. It is possible to set a wake-up time from BIOS and UEFI menus, but it (probably) only allow once a day. If you need to wake the computer multiple times a day, you should use something externally. For my home lab, I have a raspberry pi 0 always on an connected to the internet. Using etherwake I send wake on lan commands to my server and desktop computer when needed.
    – Emre Talha
    Oct 2, 2022 at 19:13
  • 2
    Please do not just show the error; also include the actual command.
    – Rinzwind
    Oct 2, 2022 at 19:36

1 Answer 1

13

To suspend/hiberbate you can use

systemctl suspend
systemctl hibernate

Put it in /etc/crontab with a time you want this to happen.

1 0 * * * root /usr/bin/systemctl hibernate

For waking up a system you can use rtcwake. An example waking a system up at 4 pm/16:00:

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

You can also put this in /etc/crontab using @reboot as a trigger.

@reboot root /usr/bin/rtcwake -m no -l -t "$(/usr/bin/date -d 'today 16:00:00' '+\%s')"

You can combine the two and that would be:

0 23 * * *  root /usr/bin/rtcwake -m disk -s 60*60*12

so at 23:00 it will suspend and wake up 60 * 60 * 12 seconds (12 hours) later.

Mind that there is a possible conflict: if the system is busy doing something it will stop that and continue with suspending. There are also tools that do not suspend if there is activity, like autosuspend sudo apt install autosuspend.

7
  • Definitely learnt a lot from this, thank you so much! However it seems for my one I had to do sudo rather than root, is this depending on the distro I am using or is root also supposed to work?
    – Jo-El
    Oct 4, 2022 at 12:47
  • @Jo-El as of today I can reboot my notebook using a galaxy smartwatch :D That could work too for you but you need to be in "range" of your system (ie. 5 mtr for BT and in the same network for wifi or if possible to add a sim card to your machine using your phone ;-) )
    – Rinzwind
    Oct 4, 2022 at 13:40
  • 1
    Oh and thanks for the accepted vote :D You have the honor of giving me the reputation to pass Oli as the #1 on AU.
    – Rinzwind
    Oct 4, 2022 at 13:41
  • Haha I'm glad I made your day man, it's well deserved.
    – Jo-El
    Oct 7, 2022 at 15:43
  • And that is an amazing project that you completed there man congratulations, I'm going to add this to my future project list
    – Jo-El
    Oct 7, 2022 at 15:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .