Run script on startup, halt, reboot

By xngo on February 24, 2019

chmod +x yourscript.sh
cp yourscript.sh /etc/init.d/
cd /etc/init.d/
update-rc.d yourscript.sh start 20 0 6 .
 
# Runlevel
#  0=halt
#  6=reboot

Ignore message insserv: warning: script 'yourscript.sh' missing LSB tags and overrides. This warning appears because yourscript.sh format doesn't conform to LSB init script.

Reference

  • https://wiki.debian.org/LSBInitScripts
  • http://www.linuxquestions.org/questions/debian-26/run-this-command-when-the-computer-shutdown-or-reboot-683851/
  • http://en.wikipedia.org/wiki/Runlevel

About the author

Xuan Ngo is the founder of OpenWritings.net. He currently lives in Montreal, Canada. He loves to write about programming and open source subjects.