A few words of thanks would be greatly appreciated.

Execute a Script at Startup and Shutdown on Ubuntu

When using Ubuntu, user-defined tasks can be performed by executing a script at startup and shutdown. Each of these scripts is a little particular and requires subtle modifications in order to include additional commands.

This article will show you how to execute scripts upon startup, reboot, and shutdown on an Ubuntu system. Please note that scripts are run in the alphabetical order in directories, and all scripts should be named following Linux's nomenclature rules. Only then will they run properly.

How To Execute a Script at Startup

To execute a script at startup of Ubuntu, simply edit
, and add your commands.

Note that the script must always end with
exit 0

How To Execute a Script Upon Rebooting

To execute a script upon rebooting an Ubuntu system, you must write your script in
. Be sure to make the script executable by using
sudo chmod +x myscript

Note that the scripts in this directory will be executed in alphabetical order. The name of your script must begin with
to run at the right time.

How To Execute a Script at Shutdown

In order to execute a script at shutdown, you must put your script in
and make it executable through
sudo chmod +x myscript

Please note that the scripts in this directory are executed in alphabetical order. Similar to the rebooting script, the name of your rebooting script must begin with
in order to run properly and at the right time.
Jean-François Pillou

CCM is a leading international tech website. Our content is written in collaboration with IT experts, under the direction of Jeff Pillou, founder of CCM.net. CCM reaches more than 50 million unique visitors per month and is available in 11 languages.

Learn more about the CCM team

Published by jak58. Latest update on September 20, 2016 at 06:17 PM by Olivia Long.

This document, titled "Execute a Script at Startup and Shutdown on Ubuntu," is available under the Creative Commons license. Any copy, reuse, or modification of the content should be sufficiently credited to CCM (https://ccm.net/).


This does not work. Both scripts are run on shutdown and on bootup,
rc0, 1, and 6 are executed on shutdown, while
rc 2, 3, 4 and 5 are executed on startup