systemd: How to check scheduled time of a delayed shutdown?

man shutdown(8) says:

The first argument may be a time string (which is usually "now").

The time string may either be in the format "hh:mm" for hour/minutes specifying the time to execute the shutdown at, specified in 24h clock format. Alternatively it may be in the syntax "+m" referring to the specified number of minutes m from now. "now" is an alias for "+0", i.e. for triggering an immediate shutdown. If no time argument is specified, "+1" is implied.

Try:

# shutdown +5
# systemctl status systemd-shutdownd.service

You should see something like this:

● systemd-shutdownd.service - Delayed Shutdown Service
Loaded: loaded (/lib/systemd/system/systemd-shutdownd.service; static; vendor preset: enabled)
Active: active (running) since Tue 2015-09-15 09:13:11 UTC; 12s ago
Docs: man:systemd-shutdownd.service(8)
Main PID: 965 (systemd-shutdow)
Status: "Shutting down at Tue 2015-09-15 09:18:11 UTC (poweroff)..."
CGroup: /system.slice/systemd-shutdownd.service
       └─965 /lib/systemd/systemd-shutdownd

Status is Shutting down at Tue 2015-09-15 09:18:11 UTC (poweroff)...


# cat /run/systemd/shutdown/scheduled
USEC=1537242600000000
WARN_WALL=1
MODE=poweroff

The USEC is a unix epoch timestamp with microsecond precision, so:

if [ -f /run/systemd/shutdown/scheduled ]; then
  perl -wne 'm/^USEC=(\d+)\d{6}$/ and printf("Shutting down at: %s\n", scalar localtime $1)' < /run/systemd/shutdown/scheduled
fi

will display something like:

Shutting down at: Tue Sep 18 03:50:00 2018

Systemd version is 232-25+deb9u4 running on Debian Stretch .


For newer linux distributions versions you might need to do:

busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ScheduledShutdown

The method of how shutdown works has changed

Tried on: - Debian Stretch 9.6 - Ubuntu 18.04.1 LTS

References

  • Check if shutdown schedule is active and when it is
  • The shutdown program on a modern systemd-based Linux system