Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

custom shutdown script problem

Status
Not open for further replies.

hfaix

MIS
Nov 25, 2003
596
0
0
US
I've been an AIX admin for about 5 years, however I'm currently writing our Linux standards. I admit, I'm fairly green when it comes to Linux but I've read a lot about runlevels and think I have it figured out.....

I'm trying to add a custom script on RHEL5 that runs on reboot. I've written a very simple script and created a link to it in /etc/rc6.d

The problem is the script never runs. Can you help?

user@hostname:/etc/rc6.d-> ls -l /etc/init.d/custom
-rwxr-xr-x 1 root root 72 May 29 08:47 /etc/init.d/custom
user@hostname:/etc/rc6.d-> ls -l /etc/rc6.d/K74custom
lrwxrwxrwx 1 root root 16 May 29 09:10 /etc/rc6.d/K74custom -> ../init.d/custom

I've tried about 10 different numbers (after the K) but the thing still never runs. If I call my script from a currently working rc6.d script it works fine.

Here is my script.
user@hostname:/etc/rc6.d-> cat /etc/init.d/custom
#!/bin/sh
echo "reboot test" > /usr/reboot.log
date >> /usr/reboot.log









 
I am no expert but.. scripts that begin with a K are meant to be run on shutdown. Try changing your script to begin with Sxx instead.
 
oops scratch that.. this is what happens when you don't touch a Linux box for awhile..
 
I thought that when entering that run level, [tt]init[/tt] will first run all the "K" scripts, then all the "S" scripts. They are run in ASCII sorted order, so the two digits after the "K" or "S" controls the order.

So if you want something to only run in run level 3 (for example), you have the "S" script (link) in [tt]/etc/rc3.d[/tt], and the "K" scripts (links) in all of the other dirs ([tt]/etc/rc[012456S].d[/tt]).

At least that's how Solaris does it. I assume Linux is the same.

 
In addition to what SamBones pointed out:

Afaik, if you want a script to run at shutdown time, you will have to put it (or a link to it) into /etc/rc0.d.
At least this is the common Unix way; I haven't a RedHat system at hand.

And about the question why it works, if you call the script from a currently working rc6.d script:
I guess this other script is linked to rc0.d.

And if everything else fails: Reading the manual might help.
[wink]
 
Thanks for all the feedback.

I was able to get it to work. I turned it into a service, turned the service on with chkconfig, and then added a lock file to /var/lock/subsys (which I need to incorporate into my startup). It appears as though the lock file is actually what did the trick.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top