RTC wakeup on Linux
Published: 2014-09-18Most BIOSes offer the possibility to fire up your computer at a given time. This may be a handy alternative when WoL is unavailable or unreliable, but it offers little flexibility.
Linux allows you to wake up your system however you want. You can do it the hardcore way and roll your own script, using date
etc., but if you don't mind stepping out of the Stone Age, you'd better have a look at rtcwake
, which comes with the util-linux
suite (at least, in Debian Jessie). It's an all-in-one tool - it will read the clock, add the offset you want, shut down, suspend or hibernate your system. If you're unsure about what this or that option will do, there's even a dry run mode. For a full explanation, take a look at
$ man 8 rtcwake
So how does this play out in practice? It's pretty easy. Rtcwake determines what mode the hardware clock is set to (UTC, or local), and takes either seconds or an absolute Epoch time value for the wakeup delay. My brother wants his server to wake up at 18:00 during the working week, and to shut down around midnight. Say we set the shutdown at 0:30. You want the system to boot at 18:00, or 17,5 hours later - that is, in seconds: 17,5*3600 = 63000. You can drop that in a crontab:
# crontab -e
30 00 * * 1-5 /usr/sbin/rtcwake -m off -s 63000
VoilĂ , it's as simple as that. Here, you can see the system shuts down at half past midnight, every monday till friday, through rtcwake, which powers up the system again at 18:00.