Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Assistance Unsupported Software
  • Search

What command to check a scheduled timed shutdown/poweroff?

This forum covers all Gentoo-related software not officially supported by Gentoo. Ebuilds/software posted here might harm the health and stability of your system(s), and are not supported by Gentoo developers. Bugs/errors caused by ebuilds from overlays.gentoo.org are covered by this forum, too.
Post Reply
Advanced search
23 posts • Page 1 of 1
Author
Message
BoGun
n00b
n00b
Posts: 12
Joined: Sun Jul 16, 2023 2:02 pm

What command to check a scheduled timed shutdown/poweroff?

  • Quote

Post by BoGun » Tue Oct 24, 2023 10:41 am

Hi all,

Finally managed to figure out how to schedule a poweroff of my machine so that's great :-)

Using command = openrc-shutdown --poweroff [wanted time]

Problem is if I set a time/date many hours later I sometimes tend to forget about it :-/

So how can I check whether I've scheduled poweroff coming up?

I tried with some different commands that I found in different Linux forums but they all are either too old or refering to Debian based systems hence doesn't work.

Any ideas much welcomed.
Top
szatox
Advocate
Advocate
Posts: 3858
Joined: Tue Aug 27, 2013 12:35 pm

  • Quote

Post by szatox » Tue Oct 24, 2023 10:53 am

I don't know how exactly openrc-shutdown is different to regular shutdown command (which also schedules shutdown at specified time and is usable with openrc), but:
man shutdown wrote: Usually shutdown displays warnings every 15 minutes and then every minute in the last 10 minutes of the countdown until time is reached. When
-q is specified shutdown only warns at 60 minute intervals, at the 10 minute mark, at the 5 minute mark, and when the shutdown process actually happens.
These warnings are broadcasted to all users on all terminals, and also should pop up when you login.
Top
BoGun
n00b
n00b
Posts: 12
Joined: Sun Jul 16, 2023 2:02 pm

  • Quote

Post by BoGun » Tue Oct 24, 2023 11:05 am

szatox wrote:I don't know how exactly openrc-shutdown is different to regular shutdown command (which also schedules shutdown at specified time and is usable with openrc), but:
man shutdown wrote: Usually shutdown displays warnings every 15 minutes and then every minute in the last 10 minutes of the countdown until time is reached. When
-q is specified shutdown only warns at 60 minute intervals, at the 10 minute mark, at the 5 minute mark, and when the shutdown process actually happens.
These warnings are broadcasted to all users on all terminals, and also should pop up when you login.
No sorry that doesn't happen on my machine. The "and also should pop up when you login" bit I ,mean.

Also FYI; have by "trial and error" come to the conclusion that only using "shutdown" doesn't work, hence "open-rc-shutdown".
Top
grknight
Retired Dev
Retired Dev
Posts: 2560
Joined: Fri Feb 20, 2015 9:36 pm

  • Quote

Post by grknight » Tue Oct 24, 2023 12:40 pm

When using openrc-shutdown, it will create the file /run/openrc-shutdown.pid while running.
Since the "scheduled" shutdown doesn't actually exit the program, this file should still exist while a poweroff is pending.

However, there does not seem to be any indication of time remaining beyond any tty broadcasts every few minutes depending on how far out it was scheduled.

See the simple code for details.
Top
Banana
Administrator
Administrator
User avatar
Posts: 2386
Joined: Fri May 21, 2004 12:02 pm
Location: Germany
Contact:
Contact Banana
Website

  • Quote

Post by Banana » Tue Oct 24, 2023 1:09 pm

BoGun wrote:Also FYI; have by "trial and error" come to the conclusion that only using "shutdown" doesn't work, hence "open-rc-shutdown".
Only shutdown does not power off the system https://linux.die.net/man/8/shutdown
Maybe this is your problem with the command.
Forum Guidelines

PFL - Portage file list - find which package a file or command belongs to.
My delta-labs.org snippets do expire
Top
BoGun
n00b
n00b
Posts: 12
Joined: Sun Jul 16, 2023 2:02 pm

  • Quote

Post by BoGun » Wed Oct 25, 2023 8:31 am

Banana wrote:
BoGun wrote:Also FYI; have by "trial and error" come to the conclusion that only using "shutdown" doesn't work, hence "open-rc-shutdown".
Only shutdown does not power off the system https://linux.die.net/man/8/shutdown
Maybe this is your problem with the command.
No I got that, please see initial post ;-) ...I'm using " openrc-shutdown --poweroff [wanted time] "
Top
BoGun
n00b
n00b
Posts: 12
Joined: Sun Jul 16, 2023 2:02 pm

  • Quote

Post by BoGun » Wed Oct 25, 2023 8:47 am

grknight wrote:When using openrc-shutdown, it will create the file /run/openrc-shutdown.pid while running.
Since the "scheduled" shutdown doesn't actually exit the program, this file should still exist while a poweroff is pending.

However, there does not seem to be any indication of time remaining beyond any tty broadcasts every few minutes depending on how far out it was scheduled.

See the simple code for details.
Thanks for your time answering :-)

Sadly I'm a very "novice" user and reading "code" is a bit beyond my knowledge at the moment (learning all the time) but I think/hope I got you right?

So you're saying that I can sort of check if there is a pending shutdown/poweroff IF there is a file = openrc-shutdown.pid in the /run/ directory, is that correct?

And further you're saying there actually is no way of checking what scheduled time is set when it's beyond a certain time?

I've also noticed when experimenting that when I set a time just a few miniutes forward I immediately get a "confirmation message" in the CLI but this doesn't happen when I set many hours forward. That's a bit odd one would think?

Edit;FYI: noticed some more odd things; seemingly when seting a time many hours forward and as mentioned earlier not recieving a "confimation message" it seems that it's not possible to cancel with " openrc-shutdown -c " while when setting time just a few minutes forward and hence recieving the confirmationg it's suddenly possible cancel with the same command ... :? well as said, beyond my knowledge.
Top
szatox
Advocate
Advocate
Posts: 3858
Joined: Tue Aug 27, 2013 12:35 pm

  • Quote

Post by szatox » Wed Oct 25, 2023 9:27 am

You are the odd one :lol: This behavior you observe in shutdown may be inconsistent (which I agree usually is a bad thing), but it does actually make sense considering what it's used for.
A scheduled shutdown is something you do on servers and mainframes to let the users finish their running tasks or save progress on whatever they're working on. It can prevent new users from logging in too. It's actually quite common for servers to disable ssh login for non-root users after shutdown has been scheduled.
There is no need to "notify users in advance" on your own PC; you already know you're shutting it down, and init will notify the processes and wait for them to terminate before pulling the plug.

Which brings up a question: Why do you want to schedule shutdown many hours ahead in the first place? Just "shutdown -h now" when you're ready for the result to take place.
If you're doing something really fancy, perhaps scheduling with crontab (for recurring jobs) or at (for one-shots) would be a better option?
Top
grknight
Retired Dev
Retired Dev
Posts: 2560
Joined: Fri Feb 20, 2015 9:36 pm

  • Quote

Post by grknight » Wed Oct 25, 2023 1:05 pm

BoGun wrote:And further you're saying there actually is no way of checking what scheduled time is set when it's beyond a certain time?

I've also noticed when experimenting that when I set a time just a few miniutes forward I immediately get a "confirmation message" in the CLI but this doesn't happen when I set many hours forward. That's a bit odd one would think?

Edit;FYI: noticed some more odd things; seemingly when seting a time many hours forward and as mentioned earlier not recieving a "confimation message" it seems that it's not possible to cancel with " openrc-shutdown -c " while when setting time just a few minutes forward and hence recieving the confirmationg it's suddenly possible cancel with the same command ... :? well as said, beyond my knowledge.
The code says it sends a TTY broadcast according to the following schedule:
  • If greater than 180 minutes, send 60 minutes apart until under 180 minutes remain
  • Then, if greater than 60 minutes, send 30 minutes apart until under 60 minutes remain
  • Then, if greater than 10 minutes, send 15 minutes apart until under 10 minutes remain
  • Finally, send once a minute
This all assumes that openrc-shutdown is running the entire time. It won't exit on its own and the terminal/tty that starts it must remain.
Last edited by grknight on Wed Oct 25, 2023 7:26 pm, edited 1 time in total.
Top
Zucca
Administrator
Administrator
User avatar
Posts: 4692
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Wed Oct 25, 2023 6:17 pm

szatox wrote:I don't know how exactly openrc-shutdown is different to regular shutdown command
If you have USE="sysv-utils" for openrc, then you'll get this:

Code: Select all

#!/bin/sh

do_halt=false
while getopts :akrhPHfFnct: opt; do
        case "$opt" in
                a) ;;
                k) ;;
                r)
                        shutdown_arg=--reboot
                        ;;
                h)
                        do_halt=true
                        shutdown_arg=--poweroff
                        ;;
                P)
                        if ! ${do_halt}; then
                                printf "%s\n" "The -P flag requires the -h flag" >&2
                                exit 1
                        fi
                        shutdown_arg=--poweroff
                        ;;
                H)
                        if ! ${do_halt}; then
                                printf "%s\n" "The -H flag requires the -h flag" >&2
                                exit 1
                        fi
                        shutdown_arg=--halt
                        ;;
                f) ;;
                F) ;;
                n) ;;
                c) ;;
                t) ;;
                [?]) printf "%s\n" "${0##*/}: invalid command line option" >&2
                exit 1
                ;;
        esac
done
shift $((OPTIND-1))

if [ -z "${shutdown_arg}" ]; then
        shutdown_arg=--single
fi

printf "%s %s\n" "/sbin/openrc-shutdown ${shutdown_arg}" "$@"
exec /sbin/openrc-shutdown ${shutdown_arg} "$@"
So it's basically the same, but mostly used in setups where init=/sbin/openrc-init.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
szatox
Advocate
Advocate
Posts: 3858
Joined: Tue Aug 27, 2013 12:35 pm

  • Quote

Post by szatox » Wed Oct 25, 2023 8:36 pm

I still use openrc with sysvinit and both shutdowns are ELF binaries on my system (and they are different sizes). Huh... Learn something every day.
Probably doesn't really matter anyway though :lol:
Top
Zucca
Administrator
Administrator
User avatar
Posts: 4692
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Wed Oct 25, 2023 9:11 pm

szatox wrote:Probably doesn't really matter anyway though :lol:
There's the point right there. ;)
Like with many things in life (Gentoo), use what fits best for you. ;)
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
sabayonino
Veteran
Veteran
User avatar
Posts: 1072
Joined: Tue Jan 03, 2012 5:46 pm
Contact:
Contact sabayonino
Website

  • Quote

Post by sabayonino » Wed Oct 25, 2023 10:25 pm

A simple root cronjob istance :

Edit root cronjob

Code: Select all

# crontab -e

Edit and Test the shutdown command (-k option) to shutdown your system every day at 22.30

Code: Select all

30 22 * * * shutdown -k -t 300 -h now  "Gentoo will be power off ...save your work !!"
To test the shutdown istance , run this every minutes

Code: Select all

* * * * * blah blah
If it forks , remove the "-k" option to the root cronjob command line and set your time to shutdown

Code: Select all

crontab -e
-k --> fake shutdown (remove this flag if your script works )
-t 300 ---> delay in seconds (300 secs = 5 minutes) between the warning message and the shutdown action

see

Code: Select all

shutdown --help
The warning message will be send to all users/tty or local message broadcasting if available

cheers


[hr]
Broadcast message from root@gentoo-18 (Thu Oct 26 00:28:01 2023):

Gentoo will be power off...save your work !!
The system is going down for system halt NOW!
LRS 64/32
Top
grknight
Retired Dev
Retired Dev
Posts: 2560
Joined: Fri Feb 20, 2015 9:36 pm

  • Quote

Post by grknight » Wed Oct 25, 2023 11:59 pm

sabayonino wrote:Edit and Test the shutdown command (-k option) to shutdown your system every day at 22.30

Code: Select all

30 22 * * * shutdown -k -t 300 -h now  "Gentoo will be power off ...save your work !!"
Except this will shutdown immediately with openrc-shutdown. -t and -k are ignored. Not to mention the quoted text may throw an error.
Top
BoGun
n00b
n00b
Posts: 12
Joined: Sun Jul 16, 2023 2:02 pm

  • Quote

Post by BoGun » Thu Oct 26, 2023 8:41 am

:o :lol: :lol: :)

OMG my "little question" has gone way beyond my tiny little knowledge.

i'm feeling humlbed of you clever guys knowledge.

@ grknight; re. yours "It won't exit on its own and the terminal/tty that starts it must remain."

I'm not 100% sure I understand you right but if you mean that one needs to have the terminal window open on the machine from where I send the command to actually get it to work on the remote machine it seemingly works anyway, e.g if I send the command to remote machine and close down terminal on my sending machine the remote will shutdown. I just tested it. Allthough only with a shutdown just a few minutes forward.

@ szatox; "Huh... Learn something every day. " ...so true! :)

Also sorry if my english isn't 100%, it's not my native language.
Top
sabayonino
Veteran
Veteran
User avatar
Posts: 1072
Joined: Tue Jan 03, 2012 5:46 pm
Contact:
Contact sabayonino
Website

  • Quote

Post by sabayonino » Thu Oct 26, 2023 10:52 am

grknight wrote:
sabayonino wrote:Edit and Test the shutdown command (-k option) to shutdown your system every day at 22.30

Code: Select all

30 22 * * * shutdown -k -t 300 -h now  "Gentoo will be power off ...save your work !!"
Except this will shutdown immediately with openrc-shutdown. -t and -k are ignored. Not to mention the quoted text may throw an error.
I don't know about openrc-shutdown comnd but what I posted works locally (and on eemote machine ).

I don't know how to monitor the remote process through remote machine (telnet ? ssh ? ...)

reading the previous post of BoGun I suppose he want to monitoring the remote shutdown process :roll:
LRS 64/32
Top
Zucca
Administrator
Administrator
User avatar
Posts: 4692
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Thu Oct 26, 2023 11:16 am

sabayonino wrote:I don't know about openrc-shutdown comnd

Code: Select all

Usage: openrc-shutdown -c | --cancel
   or: openrc-shutdown -R | --reexec
   or: openrc-shutdown -w | --write-only
   or: openrc-shutdown -H | --halt time
   or: openrc-shutdown -K | --kexec time
   or: openrc-shutdown -p | --poweroff time
   or: openrc-shutdown -r | --reboot time
   or: openrc-shutdown -s | --single time

Options: [ cdDfFHKpRrswChqVv ]
  -c, --cancel                      cancel a pending shutdown
  -d, --no-write                    do not write wtmp record
  -D, --dry-run                     print actions instead of executing them
  -H, --halt                        halt the system
  -K, --kexec                       reboot the system using kexec
  -p, --poweroff                    power off the system
  -R, --reexec                      re-execute init (use after upgrading)
  -r, --reboot                      reboot the system
  -s, --single                      single user mode
  -w, --write-only                  write wtmp boot record and exit
  -h, --help                        Display this help output
  -C, --nocolor                     Disable color output
  -V, --version                     Display software version
  -v, --verbose                     Run verbosely
  -q, --quiet                       Run quietly (repeat to suppress errors)
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
sabayonino
Veteran
Veteran
User avatar
Posts: 1072
Joined: Tue Jan 03, 2012 5:46 pm
Contact:
Contact sabayonino
Website

  • Quote

Post by sabayonino » Thu Oct 26, 2023 11:30 am

Zucca wrote:
sabayonino wrote:I don't know about openrc-shutdown comnd

Code: Select all

Usage: openrc-shutdown -c | --cancel
   or: openrc-shutdown -R | --reexec
   or: openrc-shutdown -w | --write-only
   or: openrc-shutdown -H | --halt time
   or: openrc-shutdown -K | --kexec time
   or: openrc-shutdown -p | --poweroff time
   or: openrc-shutdown -r | --reboot time
   or: openrc-shutdown -s | --single time

Options: [ cdDfFHKpRrswChqVv ]
  -c, --cancel                      cancel a pending shutdown
  -d, --no-write                    do not write wtmp record
  -D, --dry-run                     print actions instead of executing them
  -H, --halt                        halt the system
  -K, --kexec                       reboot the system using kexec
  -p, --poweroff                    power off the system
  -R, --reexec                      re-execute init (use after upgrading)
  -r, --reboot                      reboot the system
  -s, --single                      single user mode
  -w, --write-only                  write wtmp boot record and exit
  -h, --help                        Display this help output
  -C, --nocolor                     Disable color output
  -V, --version                     Display software version
  -v, --verbose                     Run verbosely
  -q, --quiet                       Run quietly (repeat to suppress errors)
I know the help of the command but I have never had the opportunity to use openrc-* :wink:
LRS 64/32
Top
Zucca
Administrator
Administrator
User avatar
Posts: 4692
Joined: Thu Jun 14, 2007 10:31 pm
Location: Rasi, Finland
Contact:
Contact Zucca
Website

  • Quote

Post by Zucca » Thu Oct 26, 2023 12:54 pm

sabayonino wrote:I know the help of the command but I have never had the opportunity to use openrc-* :wink:
I meant to give you the list of arguments which openrc-shutdown accepts. :wink:
Since openrc-shutdown doesn't support -k, then maybe wall (for example) sholud be used first, then wait and finally run the actual shutdown.
..: Zucca :..

Code: Select all

init=/sbin/openrc-init
-systemd -logind -elogind seatd
I am NaN! I am a man!
Top
BoGun
n00b
n00b
Posts: 12
Joined: Sun Jul 16, 2023 2:02 pm

  • Quote

Post by BoGun » Fri Oct 27, 2023 9:40 am

BoGun wrote: e.g if I send the command to remote machine and close down terminal on my sending machine the remote will shutdown. I just tested it. Allthough only with a shutdown just a few minutes forward
Sorry I made a mistake so have to correct my "e.g if I send the command to remote machine and close down terminal on my sending machine the remote will shutdown. I just tested it. Allthough only with a shutdown just a few minutes forward." this is not true! It actually works as "grknight" explained, e.g if terminal is shutdown on sending machine after giving the command absolutely nothing happens on the remote. E.g it does not power off at set time.

Which rises a new question for me, is there any way to set a power off timer and being able to shut down the sending terminal? Real reason I want to shut down terminal has actually more to do with that I want to power off the sending machine after giving the command. But from reading what "grkninght" explains about the openrc-shutdown command I guess not possible?
Top
szatox
Advocate
Advocate
Posts: 3858
Joined: Tue Aug 27, 2013 12:35 pm

  • Quote

Post by szatox » Fri Oct 27, 2023 11:55 am

BoGun, check out "screen", it's very convenient when working on remote machines, since it maintains your session (so you don't get logged out and programs keep running) when your connection breaks, and you can later re-attach your virtual terminal and continue.
Other options are:
nohup command &
command & disown $! (AFAIR this one requires you to redirect input and outputs yourself; nohup does it automagically)

I have seen shutdown release terminal immediately too, though I think it was on binary distros using systemd. I don't know whether it was a config option or implementation detail.
Top
BoGun
n00b
n00b
Posts: 12
Joined: Sun Jul 16, 2023 2:02 pm

  • Quote

Post by BoGun » Sat Oct 28, 2023 3:34 pm

szatox wrote:BoGun, check out "screen", it's very convenient when working on remote machines, since it maintains your session (so you don't get logged out and programs keep running) when your connection breaks, and you can later re-attach your virtual terminal and continue.
Other options are:
nohup command &
command & disown $! (AFAIR this one requires you to redirect input and outputs yourself; nohup does it automagically)

I have seen shutdown release terminal immediately too, though I think it was on binary distros using systemd. I don't know whether it was a config option or implementation detail.
Many thanx szatox, looked into your suggestions but I'm afraid it's beyond my knowledge. But when / if time permits I will try / look harder.

Cherrs.
Top
szatox
Advocate
Advocate
Posts: 3858
Joined: Tue Aug 27, 2013 12:35 pm

  • Quote

Post by szatox » Sat Oct 28, 2023 5:56 pm

I'll give you a hint for screen:

This is how you start:
screen -DR

This is how you take a break:
Ctrl+A followed by D

This is how you switch to scrollback:
Ctrl+A followed by [

It allows much more, but those 3 things above are all you need for the most basic functionality. Have fun!
Top
Post Reply

23 posts • Page 1 of 1

Return to “Unsupported Software”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic