learner
28th May 2008, 21:46
Hi,
Question is related to HP Unix. I need to execute some commands in STARTUP/SHUTDOWN for my UNIX Server. Which is the script which i need to modify in Unix, so that when the Unix server STARTS/SHUTDOWNS, the desired command is executed.
Regards
Learner
Markus Schmitz
29th May 2008, 10:12
Hi learner,
in the Hp-Ux philosphy you should not add code to an existding script, but add your own start/stop script. Here how it works:
a) You write a single script, which takes as arguments at least the keywords "stop/start". You place this script in /sbin/init.d
In /sbin/init.d you also find tons of example for such a script. A good and simple starting point is to make a copy of the "cron" script, which is used to start the cron daemon.
b) Usually such scripts source an environemnt file in /etc/rc.config.d, which might specify a flag, whether the service is supposed to be started at boot time or not. Again a good start is the "cron" script to look at.
c) Now you create links in /sbin/rcX.d to your first script. If this link starts with a "S" it is interpreted as a start script, if it starts with a "K" it is interpreted as the stop script. Example:
/sbin/rc2.d/S200baan pointing to /sbin/init.d/baan
---> this will execute the baan script with the "start" argument, when going into run level 2
/sbin/rc3.d/K800baan pointing to /sbin/init.d/baan
---> this will execute the baan script with the "stop" argument when leaving run level 3
The scripts are executed relative to other scripts in these directories according to the alphabetical order, therefore the numbers 200 and 800. It is common practice to make sure, that the numbers of the start and stop script add to 1000. This guarentees that the services are stopped in the reverse order as they are started.
A bit complicated? yes. But once you get the hang of it, very easy to do.
Regards
Markus
learner
29th May 2008, 18:21
Hi Markus,
Thanks a ton for the info, well probably i guess its not that complicated since you explained quiet beautifully :-) more than expected.
I will try the same & get back to u all in case if i face any issues.
Regards
Learner