Red HatThis forum is for the discussion of Red Hat Linux.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I don't know with distro do you use, but most distros have some rcX.d directories at /etc or at /etc/something. Scripts on those dirs run on a specific order (the scipts at rcX.d where X is a number run on the natural order from 1 to 5).
Each one of those directories have files nammed as SXX* or KXX*, where XX is a 2 digit number. The scripts that start with K run first, receiving the argument "stop". Then, the scripts that start with S run, receiving the argument "start". The order that the K and S scripts run are given by their numbers, so it is K00*, K01*, ..., K99*, S00*, S01*, ..., S99*.
You need to discover where the scripts that depend on your are and make sure it runs first.
Thing is, my script runs and then stops - if something ran it with the argument 'stop', it would just run again.
If it starts a service, you should name it SXX*, if it stops one, you should name it KXX*. If it just set some configuration, or anything that doesn't deal with deamons, you should name it SXX*. But the name is not so restrct, the only differences between them are the order of execution and the argument, any one will work fine (but your system will be hard to understand if you use a K script to start something or a S one to stop).
I have directories 0 thru 6, which I'm assuming refer to the runlevels.
Yes, those directories refer to runlevels. There may also be a rcS.d that refer to runlevel S (the one that executes before 0), but I am not sure, because they usualy start at 1 (so, on your system, S may be 0). You put your script everywere you need it to run. So, if you need it to run once, before some others (that depend on it), put it on a place that will be reached before the others. If you need to run it every runlevel, put it on every runlevel, but remember that runlevel S always run, and that runlevels 1 to 6 run everytime you reach a runlevel bigger or equal to them. That mean, if your system is going untill runlevel 5, it runs, on that order, runlevels S, 0, 1, 2, 3, 4 and 5, so, it is very rare to need something on all of them. I would recommend you to put your script with a number as hight as possible (to make it execute as late as possible), so it interferes with as little others as possible. Runlevel S is special because, when you type linux single at Lilo prompt, you just run it, so, if you want your script to run even if you are on a single section, you need to put it there.
Also, notice that those directories only have symbolic links. This is the usual way to add scripts to them, the script is located at /etc/init.d and is linked from the directories that you want.