Run a script or command during shutdown

Need some help with your shiny new breakout board, or something not working right? Let us help you here!
Post Reply
rownie23
n00b
Posts: 2
Joined: Mon Jan 21, 2019 3:59 pm

Run a script or command during shutdown

Post by rownie23 » Mon Jan 21, 2019 4:03 pm

Hello, this is my first post here and I'm very to new to Raspberry Pi so please bear with me if I'm asking something simple.

Basically, it's like this:
The application I'm using my Raspberry Pi on needs to issue a command "killall -9 erni" to ensure that particular process is stopped before the safe shut down completes and the SD card is protected as per usual.

Is this something that can be done? Any pointers would be very appreciated!

Thanks! :)

User avatar
Dave
ModMyPi
Posts: 2955
Joined: Wed Jul 22, 2015 11:36 am
Contact:

Re: Run a script or command during shutdown

Post by Dave » Wed Jan 23, 2019 9:17 am

rownie23 wrote:
Mon Jan 21, 2019 4:03 pm
Hello, this is my first post here and I'm very to new to Raspberry Pi so please bear with me if I'm asking something simple.

Basically, it's like this:
The application I'm using my Raspberry Pi on needs to issue a command "killall -9 erni" to ensure that particular process is stopped before the safe shut down completes and the SD card is protected as per usual.

Is this something that can be done? Any pointers would be very appreciated!

Thanks! :)
You can just chain the two commands together into a single line using the semi-colon ;

Code: Select all

sudo sh -c "killall -9 erni ; shutdown -h now"
Forum Administrator & Technical Support

rownie23
n00b
Posts: 2
Joined: Mon Jan 21, 2019 3:59 pm

Re: Run a script or command during shutdown

Post by rownie23 » Mon Feb 11, 2019 10:52 am

Thank you for the response, I'm pleased to hear that it can be done. But how do I get a script to run when the PIco UPS starts to safely shutdown?

User avatar
Dave
ModMyPi
Posts: 2955
Joined: Wed Jul 22, 2015 11:36 am
Contact:

Re: Run a script or command during shutdown

Post by Dave » Wed Feb 13, 2019 9:27 am

You can edit the fssd script

Code: Select all

PiModules\code\python\upspico\picofssd\build\scripts-2.7\picofssd
You should be able to find the shutdown command within the script

Code: Select all

        if not GPIO.input(PULSE_PIN):
            # pin is low, this is shutdown signal from pico
            self.counter += 1
            self.log.warning("Lost power supply, Pi will shutdown")
            self.alert_email()
            time.sleep(2)
            os.system('/sbin/shutdown -h now')

Code: Select all

os.system('/sbin/shutdown -h now')
You can then add your command just before it
Forum Administrator & Technical Support

Post Reply