How to schedule system reboot

It is a short entry, but an useful one, as it is important to have a basic knowledge of how to schedule system reboot or power it down automatically at specified time.

Schedule operation

Reboot system now.

$ sudo shutdown -r now

Shutdown system now.

$ sudo shutdown -P now

Reboot system at 14:30.

$ sudo shutdown -r 14:30

Shutdown system after 80 minutes.

$ shutdown -P +80

Cancel pending operation.

$ shutdown -c

Verify pending operation on Debian Jessie (systemd 215).

$ cat /run/systemd/shutdown/scheduled

Verify operation

Verify pending operation on Ubuntu Wily Werewolf using D-Bus.

$ qdbus  --literal --system org.freedesktop.login1  /org/freedesktop/login1 org.freedesktop.DBus.Properties.Get org.freedesktop.login1.Manager ScheduledShutdown
[Variant: [Argument: (st) "poweroff", 1445770800000000]]
Note that this timestamp is in microseconds (1/1000000 second).

Use date and bc commands to pretty print scheduled date.

$ date -d @$(echo "(1445770800000000/1000000)" | bc)
Sun Oct 25 12:00:00 CET 2015

This operation can be divided into two steps.

$ echo "(1445770800000000/1000000)" | bc
$ date -d @1445770800
Sun Oct 25 12:00:00 CET 2015
Please verify that you can rely on /run/systemd/shutdown/scheduled file as it is not deleted after the whole operation is aborted using Ubuntu 15.10 and systemd 225.
Milosz Galazka's Picture

About Milosz Galazka

Milosz is a Linux Foundation Certified Engineer working for a successful Polish company as a system administrator and a long time supporter of Free Software Foundation and Debian operating system.

Gdansk, Poland