?
Solved

Custom script on startup

Posted on 2001-08-14
5
Medium Priority
?
296 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 80 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 80 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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

Network Interface Card (NIC) bonding, also known as link aggregation, NIC teaming and trunking, is an important concept to understand and implement in any environment where high availability is of concern. Using this feature, a server administrator …
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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…
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.
Suggested Courses

719 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