View previous topic :: View next topic |
Author |
Message |
BoGun n00b

Joined: 16 Jul 2023 Posts: 12
|
Posted: Tue Oct 24, 2023 10:41 am Post subject: What command to check a scheduled timed shutdown/poweroff? |
|
|
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. |
|
Back to top |
|
 |
szatox Advocate

Joined: 27 Aug 2013 Posts: 3517
|
Posted: Tue Oct 24, 2023 10:53 am Post subject: |
|
|
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. |
|
Back to top |
|
 |
BoGun n00b

Joined: 16 Jul 2023 Posts: 12
|
Posted: Tue Oct 24, 2023 11:05 am Post subject: |
|
|
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". |
|
Back to top |
|
 |
grknight Retired Dev

Joined: 20 Feb 2015 Posts: 2028
|
Posted: Tue Oct 24, 2023 12:40 pm Post subject: |
|
|
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. |
|
Back to top |
|
 |
Banana Moderator


Joined: 21 May 2004 Posts: 1902 Location: Germany
|
|
Back to top |
|
 |
BoGun n00b

Joined: 16 Jul 2023 Posts: 12
|
Posted: Wed Oct 25, 2023 8:31 am Post subject: |
|
|
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] " |
|
Back to top |
|
 |
BoGun n00b

Joined: 16 Jul 2023 Posts: 12
|
Posted: Wed Oct 25, 2023 8:47 am Post subject: |
|
|
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. |
|
Back to top |
|
 |
szatox Advocate

Joined: 27 Aug 2013 Posts: 3517
|
Posted: Wed Oct 25, 2023 9:27 am Post subject: |
|
|
You are the odd one 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? |
|
Back to top |
|
 |
grknight Retired Dev

Joined: 20 Feb 2015 Posts: 2028
|
Posted: Wed Oct 25, 2023 1:05 pm Post subject: |
|
|
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 |
|
Back to top |
|
 |
Zucca Moderator


Joined: 14 Jun 2007 Posts: 3955 Location: Rasi, Finland
|
Posted: Wed Oct 25, 2023 6:17 pm Post subject: |
|
|
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: contents of /sbin/shutdown: | #!/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 :..
My gentoo installs: | init=/sbin/openrc-init
-systemd -logind -elogind seatd |
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
 |
szatox Advocate

Joined: 27 Aug 2013 Posts: 3517
|
Posted: Wed Oct 25, 2023 8:36 pm Post subject: |
|
|
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  |
|
Back to top |
|
 |
Zucca Moderator


Joined: 14 Jun 2007 Posts: 3955 Location: Rasi, Finland
|
Posted: Wed Oct 25, 2023 9:11 pm Post subject: |
|
|
szatox wrote: | Probably doesn't really matter anyway though  | There's the point right there.
Like with many things in life (Gentoo), use what fits best for you.  _________________ ..: Zucca :..
My gentoo installs: | init=/sbin/openrc-init
-systemd -logind -elogind seatd |
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
 |
sabayonino Veteran


Joined: 03 Jan 2012 Posts: 1050
|
Posted: Wed Oct 25, 2023 10:25 pm Post subject: |
|
|
A simple root cronjob istance :
Edit root cronjob
Edit and Test the shutdown command (-k option) to shutdown your system every day at 22.30
Code: | 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: | * * * * * blah blah |
If it forks , remove the "-k" option to the root cronjob command line and set your time to shutdown
-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
The warning message will be send to all users/tty or local message broadcasting if available
cheers
[hr]
Quote: |
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 |
|
Back to top |
|
 |
grknight Retired Dev

Joined: 20 Feb 2015 Posts: 2028
|
Posted: Wed Oct 25, 2023 11:59 pm Post subject: |
|
|
sabayonino wrote: | Edit and Test the shutdown command (-k option) to shutdown your system every day at 22.30
Code: | 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. |
|
Back to top |
|
 |
BoGun n00b

Joined: 16 Jul 2023 Posts: 12
|
Posted: Thu Oct 26, 2023 8:41 am Post subject: |
|
|
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. |
|
Back to top |
|
 |
sabayonino Veteran


Joined: 03 Jan 2012 Posts: 1050
|
Posted: Thu Oct 26, 2023 10:52 am Post subject: |
|
|
grknight wrote: | sabayonino wrote: | Edit and Test the shutdown command (-k option) to shutdown your system every day at 22.30
Code: | 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  _________________ LRS 64/32 |
|
Back to top |
|
 |
Zucca Moderator


Joined: 14 Jun 2007 Posts: 3955 Location: Rasi, Finland
|
Posted: Thu Oct 26, 2023 11:16 am Post subject: |
|
|
sabayonino wrote: | I don't know about openrc-shutdown comnd |
openrc-shutdown --help: | 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 :..
My gentoo installs: | init=/sbin/openrc-init
-systemd -logind -elogind seatd |
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
 |
sabayonino Veteran


Joined: 03 Jan 2012 Posts: 1050
|
Posted: Thu Oct 26, 2023 11:30 am Post subject: |
|
|
Zucca wrote: | sabayonino wrote: | I don't know about openrc-shutdown comnd |
openrc-shutdown --help: | 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-*  _________________ LRS 64/32 |
|
Back to top |
|
 |
Zucca Moderator


Joined: 14 Jun 2007 Posts: 3955 Location: Rasi, Finland
|
Posted: Thu Oct 26, 2023 12:54 pm Post subject: |
|
|
sabayonino wrote: | I know the help of the command but I have never had the opportunity to use openrc-*  | I meant to give you the list of arguments which openrc-shutdown accepts.
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 :..
My gentoo installs: | init=/sbin/openrc-init
-systemd -logind -elogind seatd |
Quote: | I am NaN! I am a man! |
|
|
Back to top |
|
 |
BoGun n00b

Joined: 16 Jul 2023 Posts: 12
|
Posted: Fri Oct 27, 2023 9:40 am Post subject: |
|
|
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? |
|
Back to top |
|
 |
szatox Advocate

Joined: 27 Aug 2013 Posts: 3517
|
Posted: Fri Oct 27, 2023 11:55 am Post subject: |
|
|
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. |
|
Back to top |
|
 |
BoGun n00b

Joined: 16 Jul 2023 Posts: 12
|
Posted: Sat Oct 28, 2023 3:34 pm Post subject: |
|
|
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. |
|
Back to top |
|
 |
szatox Advocate

Joined: 27 Aug 2013 Posts: 3517
|
Posted: Sat Oct 28, 2023 5:56 pm Post subject: |
|
|
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! |
|
Back to top |
|
 |
|