Solved

Custom script on startup

Posted on 2001-08-14
5
284 Views
Last Modified: 2013-12-15
I'm just learning RH7 and i'm wondering how I can get a shell script to run automatically when the system reboots. I know I can do a cron job BUT that will only run at a specified time, NOT during each boot.

0
Comment
Question by:myuen
5 Comments
 
LVL 17

Accepted Solution

by:
dorward earned 20 total points
ID: 6385630
Take a look at the contents of /etc/init.d/

These are the scripts that run during boot and shutdown.

Create symlinks in /etc/rc.?/ where ? is the runlevel to start on boot (Snumber) and stop on shutdown (Knumber) the scripts.
0
 
LVL 2

Assisted Solution

by:ifincham
ifincham earned 20 total points
ID: 6392134
Hi,

Under Redhat the last script that runs before you get the logon prompt is /etc/rc.d/rc.local . This script is actually intended for local customisation so is the most obvious one to use. You could either just drop you code into that script or call it from that script - all normal mounts would have already been done so all directories will be accessible by the time rc.local is run.

What doward was referring to is slighty different. On a linux system like redhat that uses sysv init, there is a system to stop and start services as run-levels change. For example run-level 3 is multi-user console and run-level 5 is multi-user X. The way it works is that you place a script in /etc/rc.d/init.d then use 'ntsysv' or '/sbin/chkconfig' to determine at which run-levels that script is 'on'. The system then puts symbolic links into the runlevel directories which show which scripts are started or stopped at that run-level. For example, the scripts referred to in /etc/rc.d/init.d/rc.3/ (I think - doing this from memory!) would be actioned when the run-level changed to 3. This is much more sophisticated than using rc.local. What you would do is create a script that accepts arguments like 'start' 'stop' and 'status' and place it in /etc/rc.d/init.d - for example /etc/rc.d/init.d/myscript . Then you use chkconfig to make it active at the runlevels you wish, e.g. :

/sbin/chkconfig --level 2345 myscript on

This does all the hard work for you, i.e. creates/updates all the symlinks for you in the runlevel directories. Sysv init is how all the redhat services are controlled :

/sbin/chkconfig --list

It all depends on how sophisticated you want to get really - by far he simplest is through rc.local .

Regards  
0
 

Expert Comment

by:CleanupPing
ID: 9086717
myuen:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.
0
 
LVL 2

Expert Comment

by:fciii
ID: 9668172
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

PAQd and points split dorward/ifincham

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

fciii
EE Cleanup Volunteer

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…

816 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now