How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?

Moderator: BarryK

Post Reply
Stogie
Posts: 59
Joined: Thu Oct 07, 2021 8:10 pm
Has thanked: 6 times
Been thanked: 8 times

How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?

Post 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!
.

Last edited by Stogie on Sat Nov 25, 2023 5:56 pm, edited 3 times in total.
User avatar
rockedge
Site Admin
Posts: 6561
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2769 times
Been thanked: 2646 times
Contact:

Re: Shell command to reliably/safely shutdown/poweroff EasyOS in X minutes?

Post 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

Code: Select all

#!/bin/sh
sleep $1
poweroff

example run for 20 minutes:

Code: Select all

shutdown 1200
Stogie
Posts: 59
Joined: Thu Oct 07, 2021 8:10 pm
Has thanked: 6 times
Been thanked: 8 times

Re: How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?

Post by Stogie »

.
Thanks rockedge! I re-wrote my original post for more clarity as you were replying, sorry for any confusion! 8-)

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!
.

Stogie
Posts: 59
Joined: Thu Oct 07, 2021 8:10 pm
Has thanked: 6 times
Been thanked: 8 times

Re: How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?

Post 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?
.

User avatar
rockedge
Site Admin
Posts: 6561
Joined: Mon Dec 02, 2019 1:38 am
Location: Connecticut,U.S.A.
Has thanked: 2769 times
Been thanked: 2646 times
Contact:

Re: How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?

Post 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.

User avatar
fredx181
Posts: 3100
Joined: Tue Dec 03, 2019 1:49 pm
Location: holland
Has thanked: 377 times
Been thanked: 1323 times
Contact:

Re: How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?

Post 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.

Stogie
Posts: 59
Joined: Thu Oct 07, 2021 8:10 pm
Has thanked: 6 times
Been thanked: 8 times

Re: How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?

Post 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 pm

Yes, 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 pm

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.

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

Stogie
Posts: 59
Joined: Thu Oct 07, 2021 8:10 pm
Has thanked: 6 times
Been thanked: 8 times

Re: How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?

Post 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! :thumbup2:
.

User avatar
BarryK
Posts: 2709
Joined: Tue Dec 24, 2019 1:04 pm
Has thanked: 132 times
Been thanked: 739 times

Re: How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?

Post 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

Stogie
Posts: 59
Joined: Thu Oct 07, 2021 8:10 pm
Has thanked: 6 times
Been thanked: 8 times

Re: How to schedule (or run after X mins delay) a shell script that shuts down EasyOS and the machine?

Post by Stogie »

.
Thanks Barry! For this, and all you do with EasyOS. It's made my computing life so much easier and better!
.

Post Reply

Return to “EasyOS”