Script autostart at boot time on Linux

(Just because I came across this several times during the last weeks being asked by Linux newbees. )
If you want to have a script, a command or a program run at autostart on Linux, put it into /etc/rc.local. On my Ubuntu or Mint systems this file has the following content:

#!/bin/sh -e                                                                        
# rc.local                                                                          
# This script is executed at the end of each multiuser runlevel.                    
# Make sure that the script will “exit 0” on success or any other                  
# value on error.                                                                  
# In order to enable or disable this script just change the execution              
# bits.                                                                            
# By default this script does nothing.                                              
exit 0   

If you add a line like echo “`date`: Hello, dude, I am just booting.” > /tmp/bootlog here, the next time your system starts you will find a timestamp followed by the nice greeting inside the file /tmp.bootlog:

Thu Dec  8 16:06:35 CET 2011: Hello, dude, I am just booting.

Mind that this only works on systems that (perhaps you’ll use locate rc.local) to check that) have the relevant init script /etc/init.d/rc.local on their hard drive. My Ubuntu/Mint systems have the test following test included:

do_start() {
        if [ -x /etc/rc.local ]; then
                [ “$VERBOSE” != no ] && log_begin_msg “Running local boot 
scripts (/etc/rc.local)”
                [ “$VERBOSE” != no ] && log_end_msg $ES
                return $ES

Basically, this test makes sure that it is executed if it exists. If you have symbolic links like these:


then this script will be run always on the start of runlevels 2,3,4 and 5. You can change that behaviour with the command update-rc.d (a very good manpage is available).

Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: