Solved

Custom script on startup

Posted on 2001-08-14
5
282 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Daily system administration tasks often require administrators to connect remote systems. But allowing these remote systems to accept passwords makes these systems vulnerable to the risk of brute-force password guessing attacks. Furthermore there ar…
This is the error message I got (CODE) Error caused by incompatible libmp3lame 3.98-2 with ffmpeg I've googled this error message and found out sometimes it attaches this note "can be treated with downgrade libmp3lame to version 3.97 or 3.98" …
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…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

863 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

25 Experts available now in Live!

Get 1:1 Help Now