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
dongtuuyenblackpeony
n00b
Posts: 1
Joined: Wed Jun 12, 2019 11:45 am

Run a script or command during shutdown

Post by dongtuuyenblackpeony » Wed Jun 12, 2019 11:46 am

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!

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

Re: Run a script or command during shutdown

Post by Dave » Wed Jun 12, 2019 11:53 am

Are you manually issuing the shutdown command or is another script doing it?

If it's a script executing the shutdown command, then you'll just need to edit that script to add the kill command before the shutdown command.

If you are manually doing the shutdown, then you'll just need to run the kill command manually before imitating the shutdown. Or create a python script that you can run that will do the kill and the shutdown for you.

Something like this (untested):

Code: Select all

import os

os.system('sudo killall -9 erni')
os.system('sudo shutdown -h now')
Then you can just execute the script with:

Code: Select all

sudo python <scriptname>.py
Forum Administrator & Technical Support

Post Reply