Linux : How to run a command when boots up?
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
You may also be interested in other helpful articles:
- Review of Trinity Rescue Kit Live CD
- Five minutes to a secure Linux system
- Install and Run Debian Linux from an Encrypted USB Drive
- How to: Install Photoshop CS2 on Linux using Wine
- Splashtop to Ship ASUS Motherboards With Linux Preinstalled On BIOS
Discussion on This Article:
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!


Just wanna say *THANK you* to all contributeros of this blog and gr8 work. Keep it up guys!
– Robin
just want to ask…when you use the rc.local, where does the programs or scrits have to be located?
> 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.
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…