How to Add a Script to the Startup in Linux

The Linux operating system goes through different levels, called runlevels, as the system boots up. Each runlevel has a specific number and a "rc" file that is associated with it. The rc files specify the services and scripts that should be run when the system enters the corresponding runlevel. There is also an "rc.local" file that is used to reference any user specified scripts that should be started during the boot process. This file is read when the system enters the multi-user runlevel but before any users are allowed to log in.

Instructions

    • 1

      Open a terminal window or log into the computer via an SSH prompt.

    • 2

      Type the command "su -" to switch to the root user. Ubuntu users, skip this step and type "sudo" before the next command.

    • 3

      Type the command "vi rc.local" to open the rc.local file in the "Vi" text editor. You can replace "vi" with your preferred text editor.

    • 4

      Type the path to the script you want to run at the bottom of the file on its own line. For example, if your script is stored in your home directory type

      /home/your_username/start_script

      at the bottom of the rc.local file.

    • 5

      Save the file.

    • 6

      Reboot the machine to make sure the script runs correctly.

Tips & Warnings

  • If you are using Debian, you should place the script in the "/etc/init.d" directory, rather than editing the "rc.local" file.

  • If you start a service with a script during the boot process, it is recommended that you create another script that stops the service and add the script to the "/etc/rc.0" and "/etc/rc.6" files.

Related Searches:

References

Comments

Related Ads

Featured