Solved

Custom script on startup

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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" …
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 several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

758 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

19 Experts available now in Live!

Get 1:1 Help Now