30

I like to use shutdown -h TIME/+DELAY sometimes. However, since the switch to systemd (on Ubuntu), things seem to have changed quite a bit.

Apart from the fact that a previous shutdown command no longer prevents running a new one, I can't figure out how to check for the planned shutdown time of a current shutdown process.

I used to just run ps aux | grep shutdown to see the planned shutdown time.

Now with systemd it just shows something like this:

root      5863  0.0  0.0  13300  1988 ?        Ss   09:04   0:00 /lib/systemd/systemd-shutdownd

How can I check the scheduled shutdown time of such a process?

I tried shutdown -k, but instead of only writing a wall message, it seems to also change the scheduled shutdown time to now+1 minute.

3
  • 3
    Me: "surely there's a simple way to view a pending shutdown, maybe some combination of arguments to shutdown that I overlooked?" SO: "here's a bunch of awk scripts, obsolete systemd invocations, and log parsing commands that might give you the info" Me: 😳
    – Tobias J
    Dec 30, 2021 at 19:48
  • Upvoted as "useful", because yes, it should be an argument to the shutdown command! Maybe someone will see this and add it some day... :)
    – KIAaze
    Feb 25, 2022 at 12:49
  • It seems that systemd developers are not very interested in updating the shutdown as it is just a compat layer to systemd features now, see github.com/systemd/systemd/issues/11928... Mar 13, 2022 at 11:04

6 Answers 6

19
# 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 .

1
15

Most simple: (and working on Debian/Ubuntu and RedHat)

date --date @$(head -1 /run/systemd/shutdown/scheduled |cut -c6-15)
3
  • 2
    Thanks. I found the systemctl method more intuitive, but since it stopped working, this seems to be the simplest solution for newer systems. (just tested on Kubuntu 20.04) Should I accept your answer instead now? Either way, it is here for whoever might need it now. :)
    – KIAaze
    May 20, 2020 at 9:36
  • it's kind of weird, i have a schedule at 5:58PM which is 10hours from now, but using date it shows me 5:58, not 17:58
    – izzulmakin
    Mar 12, 2021 at 1:04
  • Works for me on 20.04. If no shutdown is scheduled, /run/systemd/shutdown/scheduled won't exist.
    – mwfearnley
    Feb 26, 2022 at 13:32
14

All systemd versions

Use the org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ScheduledShutdown D-Bus interface:

USECS=$(busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ScheduledShutdown | cut -d ' ' -f 3)
SECS=$((USECS / 1000000))
date --date=@$SECS

Only systemd versions < May 2015

# 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)...

1
  • There is no systemd-shutdownd.service with redhat 8.
    – Nils
    Mar 15 at 15:17
8

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

1
  • 3
    The output specifies the shutdown time as microseconds since the Unix epoch. To get a human-readable time: date -d @$(( $(busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ScheduledShutdown | cut -d' ' -f3) / 1000000 )) Jan 31, 2019 at 20:30
4

I encountered the same question and found another way to check the shutdown plan.

When you set a shutdown plan, wall will send a message to everybody logged in with their mesg permission set to yes. For every invocation of wall a notification will be written to syslog. To search the syslog, you could run the command journalctl -u systemd-shutdownd, the -u option could filter the log by unit.

When you run journalctl -u systemd-shutdownd, it will show the shutdown details like below:

[root@dev log]# journalctl -u systemd-shutdownd
-- Logs begin at Mon 2017-06-12 09:39:34 CST, end at Mon 2017-06-12 14:05:04 CST. --
Jun 12 09:39:50 dev.local systemd[1]: Started Delayed Shutdown Service.
Jun 12 09:39:50 dev.local systemd[1]: Starting Delayed Shutdown Service...
Jun 12 09:39:50 dev.local systemd-shutdownd[1249]: Shutting down at Mon 2017-06-12 21:00:00 CST (poweroff)...
Jun 12 09:55:59 dev.local systemd-shutdownd[1249]: Shutdown canceled.
Jun 12 09:56:07 dev.local systemd[1]: Started Delayed Shutdown Service.
Jun 12 09:56:07 dev.local systemd[1]: Starting Delayed Shutdown Service...
Jun 12 09:56:07 dev.local systemd-shutdownd[2885]: Shutdown canceled.
Jun 12 11:54:15 dev.local systemd[1]: Started Delayed Shutdown Service.
Jun 12 11:54:15 dev.local systemd[1]: Starting Delayed Shutdown Service...
Jun 12 11:54:15 dev.local systemd-shutdownd[3178]: Shutting down at Mon 2017-06-12 20:00:00 CST (poweroff)...
2

On an Ubuntu 18.04 machine shutdown is managed by systemd. On my machine I have enabled automatic reboots via unattended upgrades:

$ grep Automatic-Reboot /etc/apt/apt.conf.d/50unattended-upgrades
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "02:00";

The scheduled automatic reboot time is stored in /run/systemd/shutdown/scheduled.

$ cat /run/systemd/shutdown/scheduled
USEC=1563976800000000 
WARN_WALL=1
MODE=reboot

You can convert this to a human readable time using the following command:

$ date -d "@$( awk -F '=' '/USEC/{ $2=substr($2,1,10); print $2 }' /run/systemd/shutdown/scheduled )"
Thu Jul 25 02:00:00 NZST 2019

You must log in to answer this question.

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