Solved

Custom script on startup

Posted on 2001-08-14
5
287 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
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 find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
Suggested Courses

738 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