Run shell script on startup or boot

Solution 1:

The correct place for scripts that are to be run at boot is to call the script from /etc/rc.local

The comments in the file sum it up:

#!/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.

Solution 2:

You could run your script file as a Startup Application (System - Preferences - Startup Applications in Ubuntu 10.04 LTS - not sure where the equivalent is in 11.10).

For example, to run the inosync utility on bootup, I added an entry in Startup Applications with

Name=inosync
Command=/home/toaster/inosync.sh
Comment=Mirror DataDisk to Barracuda_01 

The bash script file inosync.sh must be enabled to execute. This can be achieved using sudo nautilus in Terminal, navigating to the file, right-clicking and selecting Properties, going to the Permissions tab, and checking "Allow executing file as a program".