1. Home
  2. Linux

How To Schedule Shut Down On Linux

There are many different tips and tricks on Linux that can really improve your life and productivity. One such trick is learning how to schedule shut down on Linux PC.

In this guide, we’ll go over how to schedule any Linux PC so that it automatically powers off on a schedule. Additionally, we’ll cover how to make use of the useful rtcwake tool for automatic PC wakeup!

Shutdown Tool

Powering off Linux automatically works best with the built-in shutdown tool. The shutdown program is included in all Linux distributions automatically, so there is no need to go out install it. Using it is quite straightforward and operates based on 24-hr time.

Note: not sure how 24-hr time works? Use this free conversion calculation tool.

Powering a Linux system on or off requires root privileges. Shutdown will not work correctly without a root shell. To gain root, open up a terminal and log into the root user with su. Alternatively, if su doesn’t work, try sudo -s.

su -

or

sudo -s

With root, the shutdown command now works. To turn off your Linux PC immediately, do:

shutdown -P now

Alternatively, to schedule a shutdown at a certain time, replace now with a certain time-frame. In this example, we’ll set Linux to turn itself off at exactly 19:25 Hrs (07:25 PM).

shutdown -P 19:25

At any time, a scheduled shutdown command can be canceled, using the c flag. Cancel a shutdown with:

shutdown -c

Reboot With Shutdown Tool

Using the shutdown command to automatically power off a Linux PC at a set time is handy.  However, despite its name, shutdown is capable of much more. One of the more useful features of this command is the “restart” flag. With it, the command will reboot your Linux PC on a schedule.

Using the r flag to schedule a restart with shutdown works identically to how the P flag works. Simply write out the command, specify a time, and use the flag:

shutdown -r 19:25

As always, to disable the reboot command, do shutdown -c.

Schedule Wakeups

Rtcwake is a tool that lets users suspend their PC, and schedule it to wake back up at a later time. Unlike shutdown, the rtcwake command can use different types of time schedules. Specifically, it works with both seconds and UTC (24 HR) time.

This tool has a lot of different settings and features. To get the most out of rtcwake, save the command cheatsheet to a text file for later reading.

rtcwake --help >> ~/rtcwake-help.txt

Suspend To RAM And Wake

A popular way of sleeping a PC is to suspend it to RAM. Many people go this route rather than suspending to disk as suspending to RAM offers superior power savings on laptops. With the rtcwake tool, this type of suspending can be automated. To schedule your Linux PC to automatically suspend to RAM and wake up 8 hrs later, enter the following commands.

Note: the RTCwake tool can use both seconds and UTC time. For more precise wakeups, it’s best to use seconds.

su -

or

sudo -s

rtcwake -m mem -s 28800

Suspend To Disk And wake

Prefer to suspend to Disk when you put your Linux PC to sleep? Why not schedule it with rtcwake! Gain a root shell and do the following to suspend to disk for 12 hrs.

rtcwake -m disk -s 43200

Suspend And Other Operations

Automatic sleep and wakeup is pretty useful, but what about launching programs right after wakeup? Luckily, thanks to the way Linux and UNIX work, it’s easy to pipe rtcwake into other commands. For example, to launch Libre Office directly after rtcwake comes back from suspend, run this command.

Note: when piping other commands with rtcwake, it’s best to use sudo, otherwise programs or scripts may open with the wrong user.

sudo rtcwake -m mem -s 28800 && libreoffice

Adding && tells the Bash prompt to do one operation AND another, and so on. For example, to launch multiple programs after coming back from suspend, try:

sudo rtcwake -m mem -s 2800 && libreoffice && firefox && gnome-terminal && gimp

Don’t Suspend But Wake

The rtcwake tool often immediately suspends, only to wake up later. If you’d like to suspend your Linux PC when you see fit, but schedule a wakeup, you’ll need to make use of the no feature. Using no tells rtcwake not to suspend, but to wake up on the set schedule.

Using the no flag with rtcwake means there is no need to specify the type of suspension, as the system assumes the user will do it manually later. Instead, just specify when to wake up.

su -

or

sudo -s
rtcwake -m no -s 43200

Leave a comment