Is there a simple way to run a script at shutdown? [SOLVED]

Issues and / or general discussion relating to Puppy

Moderator: Forum moderators

Post Reply
User avatar
Marv
Posts: 465
Joined: Fri Dec 20, 2019 3:09 am
Has thanked: 215 times
Been thanked: 127 times

Is there a simple way to run a script at shutdown? [SOLVED]

Post by Marv »

I'm in NoblePup64 release at the moment but this is a general question. Is there a simple way to run a script (or a couple of lines of code) when the ststem is shut down, much like the capability provided in /etc/rc.d/rc.local? I really don't want to modify then maintain an existing system script like rc.shutdown though I have done so in the past.. Might be obvious but I don't see it at the moment.

Last edited by Marv on Wed Aug 21, 2024 3:01 pm, edited 1 time in total.

My pups: LxPupSc64 and Voidpup64 with LXDE ydrv and synaptics touchpad drivers, both using small savefiles for customizations. Ydrv based NoblePup64 and Fossapup64-small (both LXDE/PCManFM with no savefiles). No fdrvs throughout. :thumbup2:

vektor_alian
Posts: 74
Joined: Thu Apr 01, 2021 12:36 am
Been thanked: 22 times

Re: Is there a simple way to run a script at shutdown?

Post by vektor_alian »

Hi Marv

When you say "simple" what do you have in mind? What is the goal?
I read the rc.local and it "seems" easy but I am usually wrong.

Thanks for giving me something new to try.

Vektor

vektor_alian
Posts: 74
Joined: Thu Apr 01, 2021 12:36 am
Been thanked: 22 times

Re: Is there a simple way to run a script at shutdown?

Post by vektor_alian »

Hi Marv

Thanks again for the brain twister.

I made a script that started Dolphin file manager and then sleep 10 and reboot and it actually worked!

Would that be simple enough?

Vektor

User avatar
bigpup
Moderator
Posts: 7301
Joined: Tue Jul 14, 2020 11:19 pm
Location: Earth, South Eastern U.S.
Has thanked: 952 times
Been thanked: 1615 times

Re: Is there a simple way to run a script at shutdown?

Post by bigpup »

@Marv

What exactly do you want the command to do?

Shutdown is not as simple a process as you may think.

There are specific things that have to happen and in a specific order.

So, specifically what you want to do is going to have to be done at a specific time in the shutdown process, depending on what it is.

The things you do not tell us, are usually the clue to fixing the problem.
When I was a kid, I wanted to be older.
This is not what I expected :o

User avatar
p310don
Posts: 386
Joined: Tue Dec 03, 2019 7:17 am
Location: Brisbane, Australia
Has thanked: 74 times
Been thanked: 114 times

Re: Is there a simple way to run a script at shutdown?

Post by p310don »

I have a script that runs on shutdown on my computer, it does a backup of the day's work and then shuts down.

Note I'm using Fatdog, but the concept is the same I assume.

I have a link to the script on my desktop, it does the network mounting and copying and then simply calls the shutdown at the end. In Fatdog that is

Code: Select all

poweroff noprompt

. Not sure what the same thing is in NoblePup, but it'd be a similar script I assume.

User avatar
Marv
Posts: 465
Joined: Fri Dec 20, 2019 3:09 am
Has thanked: 215 times
Been thanked: 127 times

Re: Is there a simple way to run a script at shutdown?

Post by Marv »

bigpup wrote: Wed Aug 21, 2024 4:57 am

@Marv

What exactly do you want the command to do?

Shutdown is not as simple a process as you may think.

There are specific things that have to happen and in a specific order.

So, specifically what you want to do is going to have to be done at a specific time in the shutdown process, depending on what it is.

All I want to do is delete/clean up some lists and cache files prior to saving to the savefile if that is selected. FWIW I'm pretty familiar with the shutdown process and have worked with the shutdown script a number of times over the last 2 decades. I do sucessfully run modified scripts is several of my pups but that means that when the core scripts change I have to re-integrate my changes. Trying to avoid that. I used the example of rc.local because it is a nice repository for user code that is invoked by the system at a specific time in the startup process but is not modified by system updates. Something analogous but for shutdown is what I'm looking for.

Last edited by Marv on Wed Aug 21, 2024 1:27 pm, edited 1 time in total.

My pups: LxPupSc64 and Voidpup64 with LXDE ydrv and synaptics touchpad drivers, both using small savefiles for customizations. Ydrv based NoblePup64 and Fossapup64-small (both LXDE/PCManFM with no savefiles). No fdrvs throughout. :thumbup2:

User avatar
Marv
Posts: 465
Joined: Fri Dec 20, 2019 3:09 am
Has thanked: 215 times
Been thanked: 127 times

Re: Is there a simple way to run a script at shutdown?

Post by Marv »

p310don wrote: Wed Aug 21, 2024 7:30 am

I have a script that runs on shutdown on my computer, it does a backup of the day's work and then shuts down.

Note I'm using Fatdog, but the concept is the same I assume.

I have a link to the script on my desktop, it does the network mounting and copying and then simply calls the shutdown at the end. In Fatdog that is

Code: Select all

poweroff noprompt

. Not sure what the same thing is in NoblePup, but it'd be a similar script I assume.

Do you invoke the script that does the backup manually or is it triggered when you start the normal shutdown process? I have a script that does what I want but I have to remember to run it prior to normal shutdown. I know I could run the cleanup script using Chron but that isn't what I need.

Thanks,

My pups: LxPupSc64 and Voidpup64 with LXDE ydrv and synaptics touchpad drivers, both using small savefiles for customizations. Ydrv based NoblePup64 and Fossapup64-small (both LXDE/PCManFM with no savefiles). No fdrvs throughout. :thumbup2:

HerrBert
Posts: 364
Joined: Mon Jul 13, 2020 6:14 pm
Location: Germany, NRW
Has thanked: 19 times
Been thanked: 135 times

Re: Is there a simple way to run a script at shutdown?

Post by HerrBert »

I have put an executable script in /etc/init.d that will do some cleanup on shutdown.
Works for me in PUPMODE=5, but i can't say if it interferes with shutdownconfig.
To execute only when shutting down it needs an additional test at the beginning:

Code: Select all

#!/bin/bash
[[ $1 != stop ]] && exit
User avatar
Marv
Posts: 465
Joined: Fri Dec 20, 2019 3:09 am
Has thanked: 215 times
Been thanked: 127 times

Re: Is there a simple way to run a script at shutdown?

Post by Marv »

HerrBert wrote: Wed Aug 21, 2024 2:52 pm

I have put an executable script in /etc/init.d that will do some cleanup on shutdown.
Works for me in PUPMODE=5, but i can't say if it interferes with shutdownconfig.
To execute only when shutting down it needs an additional test at the beginning:

Code: Select all

#!/bin/bash
[[ $1 != stop ]] && exit

That will do it. Thanks much :!:

My pups: LxPupSc64 and Voidpup64 with LXDE ydrv and synaptics touchpad drivers, both using small savefiles for customizations. Ydrv based NoblePup64 and Fossapup64-small (both LXDE/PCManFM with no savefiles). No fdrvs throughout. :thumbup2:

User avatar
mikewalsh
Moderator
Posts: 6350
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 886 times
Been thanked: 2074 times

Re: Is there a simple way to run a script at shutdown? [SOLVED]

Post by mikewalsh »

Myself, I have 2 or 3 scripts that run immediately prior to shutdown doing various things.

What I did was to "divert" the system-calls from "Shutdown" & "Re-boot" in the logout GUI to a pair of scripts I named p-poweroff.sh & p-reboot.sh. These run what I need done, then I have to confirm they've run successfully by 'OK-ing' a gxmessage window.....which won't exit until you do. (Doubtless you could set gxmessage to 'time-out' instead, but I WANT a manual 'confirm', hence why I've done it the standard way).

These scripts then pass control back to wmpoweroff & wmreboot.....and shutdown/re-boot proceeds as normal.

Works for me.

Mike. ;)

vektor_alian
Posts: 74
Joined: Thu Apr 01, 2021 12:36 am
Been thanked: 22 times

Re: Is there a simple way to run a script at shutdown? [SOLVED]

Post by vektor_alian »

So Mike,

How did you
"divert" the system-calls from "Shutdown" & "Re-boot" ?

Vektor

User avatar
bigpup
Moderator
Posts: 7301
Joined: Tue Jul 14, 2020 11:19 pm
Location: Earth, South Eastern U.S.
Has thanked: 952 times
Been thanked: 1615 times

Re: Is there a simple way to run a script at shutdown? [SOLVED]

Post by bigpup »

I have this as a shutdown icon on the desktop.

It is a simple script file, dragged onto the desktop, and gave it a icon.

One click on it and it does a complete normal shutdown.

I would think you could add commands to it, that are done, prior to the command exec wmpoweroff.
exec wmpoweroff would be the last command.

Code: Select all

#!/bin/sh
#This powers off Linux Puppy !
#
exec wmpoweroff

.

Screenshot(2).jpg
Screenshot(2).jpg (3.13 KiB) Viewed 1696 times

The things you do not tell us, are usually the clue to fixing the problem.
When I was a kid, I wanted to be older.
This is not what I expected :o

vektor_alian
Posts: 74
Joined: Thu Apr 01, 2021 12:36 am
Been thanked: 22 times

Re: Is there a simple way to run a script at shutdown? [SOLVED]

Post by vektor_alian »

Hi everybody

I do not see the difference between having a script shortcut to run a progran before shutdown and doing the same thing in /etc/rc.d which seems much more difficult.

Am I missing something? Probably.

Vektor

User avatar
Marv
Posts: 465
Joined: Fri Dec 20, 2019 3:09 am
Has thanked: 215 times
Been thanked: 127 times

Re: Is there a simple way to run a script at shutdown? [SOLVED]

Post by Marv »

vektor_alian wrote: Thu Aug 22, 2024 12:34 am

Hi everybody

I do not see the difference between having a script shortcut to run a progran before shutdown and doing the same thing in /etc/rc.d which seems much more difficult.

Am I missing something? Probably.

Vektor

Executable scripts in /etc/init.d are run at startup with a parameter of "start" passed to them. At shutdown, those executable scripts are run again with a parameter of "stop" passed to them. Per @HerrBert kind reminder above, I have placed a script there to do the required cleanup if the passed parameter is "stop". It runs with no intervention or diversion required from me and as an addition, not a modification, will easily survive updates and is readily applicable to many of my pups. Exactly the solution I was looking for and svelte at 5 lines long.

My pups: LxPupSc64 and Voidpup64 with LXDE ydrv and synaptics touchpad drivers, both using small savefiles for customizations. Ydrv based NoblePup64 and Fossapup64-small (both LXDE/PCManFM with no savefiles). No fdrvs throughout. :thumbup2:

vektor_alian
Posts: 74
Joined: Thu Apr 01, 2021 12:36 am
Been thanked: 22 times

Re: Is there a simple way to run a script at shutdown? [SOLVED]

Post by vektor_alian »

Hey Marv

" It runs with no intervention or diversion required from me"

You still need to click something to shutdown though, right?

Would a desktop shortcut not survive updates or a reboot?

Confused.

Vektor

User avatar
Marv
Posts: 465
Joined: Fri Dec 20, 2019 3:09 am
Has thanked: 215 times
Been thanked: 127 times

Re: Is there a simple way to run a script at shutdown? [SOLVED]

Post by Marv »

I just use whatever standard shutdown dialog box the particular pup offers. My goal was to change the look and feel as little as possible from the default for myself and my users. A different solution wiii be correct for different folks but this one suits me and answered my question perfectly.

My pups: LxPupSc64 and Voidpup64 with LXDE ydrv and synaptics touchpad drivers, both using small savefiles for customizations. Ydrv based NoblePup64 and Fossapup64-small (both LXDE/PCManFM with no savefiles). No fdrvs throughout. :thumbup2:

User avatar
mikewalsh
Moderator
Posts: 6350
Joined: Tue Dec 03, 2019 1:40 pm
Location: King's Lynn, UK
Has thanked: 886 times
Been thanked: 2074 times

Re: Is there a simple way to run a script at shutdown? [SOLVED]

Post by mikewalsh »

@vektor_alian :-

In my case, during my early days with Puppy - whatever the reason was! - I had a prolonged spell of Puppy's ROX 'pinboard' going AWOL at every boot. Due to my having heavily-customized desktops, this meant having to reset everything up again from scratch.....a chore with which I rapidly became disillusioned..!

I soon came to the conclusion that the best thing to do was to make a copy of the PuppyPin file - the 'dynamic', 'live' file which determines the exact coordinates, icon and function of every desktop launcher - to an external location at shutdown. Since computers are all about automation, I set everything up so that Puppy itself could automate this 'chore' for me. I also set-up a script, complete with associated Menu entry, that would "reset" the PuppyPin file back to what it was at the 'previous' shutdown IF the darned thing had gone AWOL again.

=========================

Doubtless it was something I was doing wrong myself, and NOT an inherent 'Puppy' bug. I long ago built a .pet which incorporated and installed every one of these modifications to every new Puppy I set up. This hasn't happened for years; however, these days, I have my entire first-run set-up procedure done FOR me via a script which installs/links-in every single application/externally-mounted portable application that I use on a regular basis. I fire the Puppy up for the first time; I do the initial first-run stuff; I create a save-folder, and shut down. Upon second boot, I run the 'installer' script (I have one for 64-bit Pups, and another for 32-bit Pups).

A single click, and applications/portables are all installed & linked-in, Menu entries are all set up, my desktop is set with a chosen background, icon layout, installation of pWidgets and gKrellm, JWM's tray is set-up precisely the way I like it. Yes, I DO like 'consistency'; most of my Pups are very similar in appearance - I create all my own desktop backgrounds from scratch, including 'drawing-in' the home-brewed 'docks' I first developed under Win XP.

I'm well aware that for many folks, half the 'fun' comes from setting-up and customizing an OS to suit yourself. Well, so it still is for me.....but these days, I let automation take the tedium out of it! :D

Why bother with using a computer in the first place if you DON'T automate what you can? :lol: And Marv's response above illustrates this perfectly; just because YOU may be perfectly happy with a specific solution, it doesn't automatically follow that someone else will necessarily be satisfied with the way it works. We ALL have different goals/expectations/requirements for our computing experience.

Welcome to the wonderful world of scripting....

Mike. ;)

hikohan
Posts: 26
Joined: Wed Mar 13, 2024 12:08 am
Has thanked: 1 time
Been thanked: 7 times

Re: Is there a simple way to run a script at shutdown? [SOLVED]

Post by hikohan »

Place a icon `PowerOff` on desktop, and link to bash.

Code: Select all

#!/bin/bash

# DO SOMETHING
echo "SEE YOU~"

# GO DOWN
wmpoweroff
HerrBert
Posts: 364
Joined: Mon Jul 13, 2020 6:14 pm
Location: Germany, NRW
Has thanked: 19 times
Been thanked: 135 times

Re: Is there a simple way to run a script at shutdown? [SOLVED]

Post by HerrBert »

vektor_alian wrote: Thu Aug 22, 2024 1:00 am

...
You still need to click something to shutdown though, right?
...

Not necessarily... If you use crond or automatic power off from eventmanager you don't click anything,
but the script in /etc/init.d will run anyway.

vektor_alian
Posts: 74
Joined: Thu Apr 01, 2021 12:36 am
Been thanked: 22 times

Re: Is there a simple way to run a script at shutdown? [SOLVED]

Post by vektor_alian »

Hey HerrBert

Good point.

Vektor

Post Reply

Return to “Users”