startup script for different linux versions

Posted on 2008-06-23
Last Modified: 2013-12-06
I need to write a a script that inserts a line into startup script of linux machines. I am doing this as part of installation of a software developed by me. During installation, I need to make sure that the newly installed program is part of startup script, so that it gets started automatically when the system boots. This should happen, regardless of linux version or flavour. In red hat, I used to write a script to insert a line into /etc/rc.d/rc.local and it works fine.

Now, in Suse enterprise, rc.d folder is not there in etc folder. Instead of that, rc.d shortcut is available, which points to rc.init folder. In this folder again, rc.local file is not there. Instead, notmal rc.0, rc.1 rc.2 etc are available.

Now, what is the best method to make sure that my program is whenever linux starts up? In which script should I insert lines to call my executable during startup? If rc.d and rc.local are not available in the linux version, should I create the folders and files? (One site says I can create the folder/file)

Please guide...
Question by:raj_nbr
  • 6
  • 4
LVL 14

Expert Comment

ID: 21852461

Or just put your start script in /etc/rcX.d (filename Must start with upper case "S") where X is the runlevel of the system.  It won't hurt if you put/link it in all normal runlevels ie: /etc/rc2.d /etc/rc3.d /etc/5.d ... (3 and 5 are the most common)

Contents of /etc/rc3.d and or rc5.d:


Author Comment

ID: 21853436
Thanks Mike. Some clarifications..

1. Currently, I am doing it this way.

a.  installation script looks for rc.d folder
b. It then looks for rc.local script
c. It inserts a line in the script file, which calls my program. ie: I simple add a line. The line will be the name of the executable file (with path) with commandline arguments.

This works fine in Red hat. But in Suse, in some machines, rc.d is actually a link to a folder called init.d ie: rc.s folder as such does not exist. Inside init.d, there is no file with rc.local. ie: There is no file where I can insert the my program with commandline arguments.

As I mentioned earlier, I had found some information on net, which said that, in case the file does not exist, you can simply create a file called rc.local and then insert your commands inside. When system boots up, it will execute the rc.local file created by me, automatically.

But your suggestion is that,  the best method is to write a script file, and then simply copy it to rc5.d folder inside rc.d folder. ie: in suse, write a script file, and then simply copy it to rc5.d folder inside init.d folder, since rc.d is just a link to rc.d. Any script file, copied to rc5.d folder will automatically get executed when the system starts. If I add it to rc3.d folder also, then, even though the script is present in 2 folders, it will not get executed twice. Somehow it will only get executed once, and no harm will take place.

Am I right? Please confirm...

Thanking you again..

1. If I write a script file
LVL 14

Expert Comment

ID: 21856225
The number on the rcX.d folder coresponds to the run level the system boots to.  You can usually find out by looking in inittab.  The script would only get executed once.  If the system boots to run level 5 then it will process any scripts in /etc/rc.d/rc5.d and won't touch /etc/rc.d/rc3.d.  So you could write the script and link/copy it into all normal run levels and it will execute only once, but will work regardless of the run level.  Remember that the script name you write should follow the format:
"SXXscritpname"  upper case "S" is important,  XX is a number (lower numbers execute first, I normally use 99 to have it run near the end of the boot)

EX - for Redhat and SUSE the runlevels are: (note that 3 and 5 are the most likely)

#   0 - halt (Do NOT set initdefault to this)
#   1 - Single user mode
#   2 - Multiuser, without NFS (The same as 3, if you do not have networking)
#   3 - Full multiuser mode
#   4 - unused
#   5 - X11
#   6 - reboot (Do NOT set initdefault to this)

SCO Openserver uses runlevel 2 by default, but the dir is /etc/rc2.d not /etc/rc.d/rc2.d

AIX 5.3 uses run level 2 by default and the dir is /etc/rc.d/rc2.d

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.


Author Comment

ID: 21856574
Thanks again.
Actually, the requirement is to write an installation script, that copies the executables, and inserts the lines in the startupscript to run the exucutables at startup. Users who are going to use the software will not know about the runlevel. This code will be used to automate installations, by many users.

1. So is it required to check the run-level before deciding where to copy my script to? ie: Installation script must check the run-level first and then copy the autoexecution script to the right folder. Is this right?

2. I can name my script as I want and simply copy it to the rc5.d or whatever folder I need to copy it to - right? Name doesn't matter right? As long as the default runlevel is 5 , all scripts in this folder will be run, right?

3. I again got a suggestion that, the best way to do this is to insert the code in rc.local file since it would always be executed. I was informed that, if that file was not there, then I can simply create a file with name rc.d and insert the line that calls my executable. Could you comment on this please.

Thanks again
LVL 14

Accepted Solution

mikelfritz earned 250 total points
ID: 21857265
1. You should not need to check the run level.  just create a startup script and link/copy it to both /etc/rc.d/rc3.d and /etc/rc.d/rc5.d  

2.  The name MUST start with upper case S then a two digit number - use 99 - then some unique name like this


init will only process the script if it starts with a "S" and the number determines the order in which they run.

3.  Sounds like it might work, but I don't know if all flavors will process a rc.local - however all will process the rcX.d folders.
LVL 14

Expert Comment

ID: 21857369
who -r will give you the current run level if you want to check it and then only put the script in the dir for the runlevel.

Author Comment

ID: 21869234
Just a clarification

1. I  copied the script to rc3.d and rc5.d.  Runlevel was found to be 5 when I used who -r
2. The name of the script is S99scadamonitor. The script has just one line

/etc/local/scada/scmon 2 3 40

scmon is the program and 2 3 40  are command line arguments.

3. I can click on the scipt and the script executes fine. It works in terminal mode also. The program starts normally and forks into memory as a background process.
4. But, the script doesn't get executed during startup !!! (suse enterprise)
5. If I insert "/etc/local/scada/scmon 2 3 40" in rc.local in Redhat 9, it gets executed during bootup.

Where  do you think is the mistake?

Author Comment

ID: 21869464
Guess I haven't mentioned the shell to be used to execute the script. Haven't corrected it, but then hope that is the reason. It works in rc.local since it has a shell line existing already..

Author Comment

ID: 21875689
It is not executing my script!!!!

Is there a possibility that the system is configured not to execute the scripts in rc5.d and rc3.d ? I tried starting the file with S25 instead of S99 since the last script was starting with S24, but it didnt help..

Author Comment

ID: 21894974
Anyway, after lot of research, I found a decent way to automate the start-up.

1. Check the linux flavor. If it is suse, the insert the code in bood.local, else insert it in rc.local

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need Help installing MySQL JDBC Driver on CentOS VM 9 724
what is a good general partitioning scheme for RHEL? 23 128
Ubuntu vs. Debian 4 105
Linux operating system 12 82
This article will explain how to establish a SSH connection to Ubuntu through the firewall and using a different port other then 22. I have set up a Ubuntu virtual machine in Virtualbox and I am running a Windows 7 workstation. From the Ubuntu vi…
The purpose of this article is to show how we can create Linux Mint virtual machine using Oracle Virtual Box. To install Linux Mint we have to download the ISO file from its website i.e. Once you open the link you will see …
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question