Page 1 of 1
How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?
Posted: Sat Nov 25, 2023 5:18 pm
by Stogie
.
Hi folks. I'm using Easy Buster64 2.4.1 and I have a physically-remote machine that is not immediately accessible and at a certain time each day, I need to be able to safely and reliably shutdown and poweroff the machine. Or, I can instead do a "shutdown after X minutes" arrangement instead.
I figure the best way is to make a shell script (".sh" file) that, either at a scheduled time or after X minutes of being called, issues the command that safely and reliably shuts down EasyOS and powers-off the machine.
Questions:
1. If I want to use a specific time, how do I schedule the run of a shell script file in EasyOS? Does "cron" work like on other Linux distros, or is there a special EasyOS-specific alternative way of doing it?
2. What is the best command to reliably and safely shutdown and poweroff EasyOS and the machine, so that there's no damage to background services/processes or filesystem damage, and the shutdown occurs every time without fail (no "getting stuck" etc.?)
Thanks guys!
.
Re: Shell command to reliably/safely shutdown/poweroff EasyOS in X minutes?
Posted: Sat Nov 25, 2023 5:43 pm
by rockedge
@Stogie EasyOS should support cron jobs. As a script it might work using a sleep
before the poweroff
.
the script will accept a time value on the command line. Here is a super simple example we can call shutdown
example run for 20 minutes:
Re: How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?
Posted: Sat Nov 25, 2023 5:48 pm
by Stogie
.
Thanks rockedge! I re-wrote my original post for more clarity as you were replying, sorry for any confusion!
If cron works normally like on other Linuxes, then that fact combined with your script may be all I need!
Only remaining question is, does your method safely shutdown all the stuff that needs to be shut down (e.g. background services/processes) and flush filesystem buffers and do all the other stuff needed before an actual machine poweroff can safely happen? Like I said it's a remote, inaccessible machine so damaged services or filesystem would be bad. When shutting down EasyOS manually, I see LOTS of preparatory stuff happen before the actual 'poweroff' command is performed and the machine goes dark.
Thanks a lot!
.
Re: How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?
Posted: Sat Nov 25, 2023 8:13 pm
by Stogie
.
Anybody know if it's safe to just issue the "poweroff" command with no precursor commands to safely shut down services, flush disk write caches, etc? It sounds like "poweroff" just tells the hardware to immediately power off. That sounds like a bad idea if everything is still running (and EasyOS is running from a disk, not entirely in-RAM where it wouldn't matter).
As I said above, when I manually click "Power Off computer" from the EasyOS "Shutdown" menu, I see a whole lot of "wind-down" tasks happening BEFORE I see the "poweroff" command issued which makes the system physically power off about 1 second later. There has to be a reason for all those precursor "wind-down" tasks (shutting down background services and other stuff).
Can I perhaps run the exact same script file that the GUI "Power Off Computer" calls, that does it all? That'd be quite easy, if I could! If so, what's its name, and where is it located, so I can call it myself from my scheduled shell script file?
.
Re: How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?
Posted: Sat Nov 25, 2023 11:02 pm
by rockedge
@Stogie the poweroff
command will bring the system down cleanly and is safe to use.
Can I perhaps run the exact same script file that the GUI "Power Off Computer" calls, that does it all? That'd be quite easy, if I could! If so, what's its name, and where is it located, so I can call it myself from my scheduled shell script file?
Yes I think you can. I am not 100% sure in EasyOS but look for wmexit, wmpoweroff, wmreboot
scripts or symlinks. But like I said in Easy I am not sure.
Re: How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?
Posted: Sat Nov 25, 2023 11:12 pm
by fredx181
rockedge wrote: ↑Sat Nov 25, 2023 11:02 pm
@Stogie the poweroff
command will bring the system down cleanly and is safe to use.
Yes, that's right, it's not a "hard" shutdown as you may think.
Re: How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?
Posted: Sat Nov 25, 2023 11:22 pm
by Stogie
rockedge wrote: ↑Sat Nov 25, 2023 11:02 pm@Stogie the poweroff
command will bring the system down cleanly and is safe to use.
fredx181 wrote: ↑Sat Nov 25, 2023 11:12 pmYes, that's right, it's not a "hard" shutdown as you may think.
Oh, great then! I was concerned because I found this description of the "poweroff" command on a website:
poweroff sends an ACPI signal which instructs the system to power down.
That makes it sound like it just tells the PC "power off the hardware right now!". If it's got all the additional precursor service shutdown / cache flush / etc. stuff built-in to protect the system, that's ideal! And very simple too!
rockedge wrote: ↑Sat Nov 25, 2023 11:02 pmYes I think you can. I am not 100% sure in EasyOS but look for wmexit, wmpoweroff, wmreboot
scripts or symlinks. But like I said in Easy I am not sure.
I'm looking at "wmpoweroff" right now, looks like it kills a bunch of stuff, but never actually runs the "poweroff" command itself. I'm not enough of a Linux/EasyOS expert to understand 100% of its code though. "wmexit" looks similar but is not identical. "wmreboot" I didnt' look at, as I don't need to reboot.
.
Re: How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?
Posted: Sat Nov 25, 2023 11:38 pm
by Stogie
.
Ah, looks like "wmpoweroff" is indeed what the GUI "Power-off Computer" runs when you click it! I found the following in the /etc/xdg/templates/_root_.jwmrc file:
Code: Select all
<Menu label="Shutdown" icon="shutdown24.png" height="24">
<!-- <Exit confirm="false" label="Exit to prompt" icon="prompt16.xpm" /> -->
<Program label="Power-off computer" icon="mini-stop.xpm">exec wmpoweroff</Program>
<Program label="Reboot computer" icon="mini-turn.xpm">exec wmreboot</Program>
<Menu label="Rectify" icon="mini-bug1.xpm">
<Program label="Restart X server" icon="mini-x.xpm">restartwm</Program>
<Restart label="Restart JWM" icon="mini-windows.xpm"/>
<Program label="Exit to commandline" icon="prompt16.xpm">exec wmexit</Program>
<Program label="Reboot to commandline" icon="prompt16.xpm">exec wmreboot nox</Program>
<!-- <Program label="Change Window Manager" icon="mini-windows.xpm">changewm.sh</Program> -->
</Menu>
</Menu>
Have a look at that third line. It looks like I just have to do "exec wmpoweroff" as the last line in my scheduled shell script, and that should do the exact same (obviously safe) sequence of shutdown things that a manual GUI-initiated shutdown would do. Correct me if I'm wrong, but that seems right at this point!
Again, thanks for all the help guys!
.
Re: How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?
Posted: Sun Nov 26, 2023 10:12 am
by BarryK
Yes, wmpoweroff will do it. That's in all the pups also.
Have you looked at Pschedule, in the System menu?
That is also in most of the pups. It was created by zigbert:
https://oldforum.puppylinux.com/viewtopic.php?t=22166
Re: How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?
Posted: Sun Nov 26, 2023 6:41 pm
by Stogie
.
Thanks Barry! For this, and all you do with EasyOS. It's made my computing life so much easier and better!
.