Created
January 11, 2017 19:47
-
-
Save BenSjoberg/8459c7cbeacedb2de74536866b9256ce to your computer and use it in GitHub Desktop.
Get systemd scheduled shutdown time
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Determines if a shutdown is scheuled and prints the time if so. | |
# | |
# Warning: Quick hack! Basically zero error tolerance. | |
# | |
# Designed for Ubuntu 16.04. Will probably work on other systemd-based distros, | |
# but I haven't tested it on anything else. | |
# | |
# There is almost certainly a better way to do this, but I got tired of looking. | |
# | |
# Example usage: | |
# $ shutdown -r 2:00 | |
# Shutdown scheduled for Thu 2017-01-12 02:00:00 CST, use 'shutdown -c' to cancel. | |
# $ ./when_shutdown.sh | |
# Shutdown of type "reboot" scheduled for 2017-01-12 02:00 CST | |
# $ shutdown -c | |
# $ ./when_shutdown.sh | |
# No shutdown scheduled | |
set -e | |
# Get info about the pending shutdown | |
read shutdown_type time_usec <<<$(\ | |
busctl get-property org.freedesktop.login1 /org/freedesktop/login1 org.freedesktop.login1.Manager ScheduledShutdown | \ | |
awk '{print $2 " " $3}' \ | |
) | |
if [ $time_usec -eq 0 ] | |
then | |
echo "No shutdown scheduled" | |
exit | |
fi | |
time_formatted=$(date -d @$(($time_usec/1000000)) '+%Y-%m-%d %R %Z') | |
echo "Shutdown of type $shutdown_type scheduled for $time_formatted" |
And here's a way of overloading the shutdown
command with a -w
option to basically do the above:
(a few changes in output so it matches the output used by shutdown -h <time>
)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@BenSjoberg Here's an (almost) pure awk version: