About nixCraft

Topics

Linux : How to run a command when boots up?

Posted by Vivek Gite [Last updated: July 24, 2005]

Other distribution provided the file called /etc/rc.local but Debian does not use rc.local to customize the boot process. You can use simple method as follows to customize it.

(A) Execute command at system startup
Let us assume you would like to run command called

i) Create a script called mystartup.sh in /etc/init.d/ directory(login as root)
# vi /etc/init.d/mystartup.sh

ii) Add commands to this script one by one:
#!/bin/bash
echo "Setting up customized environment..."
fortune

iii) Setup executable permission on script:
# chmod +x /etc/init.d/mystartup.sh

iv)Make sure this script get executed every time Debian Linux system boot up/comes up:
# update-rc.d mystartup.sh defaults 100

Where,
mystartup.sh: Your startup script name
defaults : The argument 'defaults' refers to the default runlevels, which are 2 through 5.
100 : Number 100 means script will get executed before any script containing number 101. Just run the command ls –l /etc/rc3.d/ and you will see all script soft linked to /etc/init.d with numbers.

Next time you reboot the system, you custom command or script will get executed via mystartup.sh. You can add more commands to this file or even call other shell/perl scripts from this file too.

(B) Execute shell script at system startup
Open the file mystartup.sh in /etc/init.d/ directory
# vi /etc/init.d/ mystartup.sh

Append your script path to the end as follows (suppose your script is /root/fw.start – script that starts firewall)

/root/fw.start

Save the file.

For more info on 'Customizing your installation of Debian GNU/Linux' visit Offical Debian DOC/FAQ

Tell us how we're doing: Please answer a few questions about your experience to help us improve nixCraft.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. Robin Says:

    Just wanna say *THANK you* to all contributeros of this blog and gr8 work. Keep it up guys!

    – Robin

  2. Anonymous Says:

    just want to ask…when you use the rc.local, where does the programs or scrits have to be located?

  3. Vivek Says:

    > just want to ask…when you use the rc.local, where does the programs or scrits have to be located?
    You have to specify the full path of command or script; you can put them into your own directory or into /etc/init.d directory.
    This script will be executed *after* all the other init scripts.
    You can put your own initialization stuff in here if you don’t
    want to do the full Sys V style init stuff.

  4. Seig Lionheart Says:

    so it can run wherever the script is located as long as the full path is specified? even if it is in /opt/?
    ok…thanks…

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.