I would like to execute two scripts, one is during start up and another one is during shutdown. I know we can add script in /etc/rc.local which will be executed on start up, but if I want to execute something on shutdown, how can I do that?

  • 2
    Jeez. How about, since it's ON the raspberry pi stack exchange we ASSUME it's for the raspberry pi and permit the question to be answered, that being the entire point of this website? It's a darned good question and should not have been closed.
    – jpw
    Jan 31, 2016 at 21:10

2 Answers 2


Take a look at runlevels. With runlevel 0, you can execute scripts on shutdown. So you need to create your script somewhere, then create a symbolic link to it in /etc/rc0.d. And be careful about permissions.

P.S : If you want to execute some scripts on reboot, it's runlevel 6.


I think what you are looking for can be found here: How to execute a shell script right b4 shuting down?

  • 1
    Thank you for your contribution. Please note however that link-only answers are discouraged as the website you're linking to might possibly vanish at some point in the future. To prevent the information from becoming unavailable, please summarize the essential parts and and provide the link as a source reference.
    – n.st
    Apr 29, 2014 at 18:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.