Operating System - HP-UX
1827288 Members
3052 Online
109717 Solutions
New Discussion

How to execute a script at startup

 
SOLVED
Go to solution
Juanjo_1
Frequent Advisor

How to execute a script at startup

Hi, I'm the admin of a HP9000 with hp-ux 10.20 and I want to run a service at startup automatically, because I'm tired to run it manually when I reboot the server.

I've also a sun server and I put the scripts I want to run automatically at startup in /etc/init.d but I don't know how to do it in hp-ux.

Thanx for the help I hope to receive,
7 REPLIES 7
Robin Wakefield
Honored Contributor

Re: How to execute a script at startup

Hi,

This related link should cover all the steps involved.

http://forums.itrc.hp.com/cm/QuestionAnswer/1,,0x0fdefef4d250d611abdb0090277a778c,00.html

rgds, Robin
RAC_1
Honored Contributor

Re: How to execute a script at startup

on hpux you put it in /sbin/init.d/

The config file for your script in /etc/rc.config.d/filename.

In filename you set variable to 0 or 1.

with 1 set it will start at boottime.
There is no substitute to HARDWORK
Jeff Schussele
Honored Contributor
Solution

Re: How to execute a script at startup

Hi Juanjo,

In HP-UX you use /sbin/init.d.
Place your script there & then link it to the dir for the necessary run level /sbin/rc2.d, /sbin/rc3.d, etc.
Call the file whatever you want in /sbin/init.d, but the links should be of the following format

Start script => SXXXname
Stop scipt => KXXXname

where XXX=three digits like S725name. The digits control the order or execution. Take a look at any of the scripts already there for proper file syntax. You normally need at least 4 sections, stop, start, stop_message & start_message. These scripts should require NO input nor terminal to run.

HTH,
Jeff
PERSEVERANCE -- Remember, whatever does not kill you only makes you stronger!
Rainer von Bongartz
Honored Contributor

Re: How to execute a script at startup


put the startup script in /sbin/init.d

lets call this script sc01

Then create a symbolic link

/sbin/rc2.d/Sxxxsc01
to
/sbin/init.d/sc01
where
xxx is a number you can choose.

When the system boots up and enters run-level 2 all scripts in /sbin/rc2.d will be executed, so will be your Sxxxsc01

Regards
Rainer
He's a real UNIX Man, sitting in his UNIX LAN making all his UNIX plans for nobody ...
Sridhar Bhaskarla
Honored Contributor

Re: How to execute a script at startup

Hi,

Look at the scripts in /sbin/init.d directory for examples. When the system comes up, it will start the scripts under /sbin/rc*.d that start with S* depending on the run level. Also during the shutdown, it brings down the processes using the scripts K* under the /sbin/rc*.d again. These are nothing but links to /sbin/init.d scripts.

So, keep your script in /sbin/init.d. Create links from /sbin/rc?.d for both K* and S* ? being the run level that you wish to run this script at.

You can also keep a switch file in /etc/rc.config.d. Define a variable in the script that gets set with /etc/rc.config.d. Again, you can look at the files under this directory and see how they control the behaviour of the scripts /sbin/init.d directory.

-Sri
You may be disappointed if you fail, but you are doomed if you don't try
S.K. Chan
Honored Contributor

Re: How to execute a script at startup

The startup script should be in /sbin/init.d and it's best that you use the file "template" in this directory to build your script. The script will look for a control file in /etc/rc.config.d which has a variable in it to enable (set to 1) or disable (set to 0) the script upon startup.
Then create the appropriate symbolic link in /sbin/rc2.d (assuming you want to start this script up at run level 2). Use the last startup sequence number. For instance if say S900ems is the existing last startup script then use S901You can manually test the script by running ..
# /sbin/init.d/myprogram start
to start it up .. and ..
# /sbin/init.d/myprogram stop
to stop it.
melvyn burnard
Honored Contributor

Re: How to execute a script at startup

There is a file in /usr/share/doc called start_up.txt which contains all the information you need to set this up.

Hope it helps
My house is the bank's, my money the wife's, But my opinions belong to me, not HP!