Operating System - HP-UX
1752660 Members
5696 Online
108788 Solutions
New Discussion

Re: Need to execute user defined script during reboot

 
shameemsoft
Frequent Advisor

Need to execute user defined script during reboot

Hi,

 

we need to collect the system information(Ex: bdf, vgdisplay etc) during reboot. 

 

we have created the script & put it in /sbin/rc2.d directory.  It is collecting the information during normal shutdown(#shutdown -ry 0 command). 

 

But it is not working when we reboot(#reboot) the host or after patch installation since it directly goes to run level 0.

 

Is there any way to execute the script during reboot or reboot after patch installation.

 

Kindly help me on this.

 

Regards

Shameem

6 REPLIES 6
Dennis Handly
Acclaimed Contributor

Re: Need to execute user defined script during reboot

>since it directly goes to run level 0.

 

Your script won't run if the system only goes to runlevel 0.

What is the exact name of the script?

What does /etc/rc.log show?

Matti_Kurkela
Honored Contributor

Re: Need to execute user defined script during reboot

What is the name of the script in /sbin/rc2.d directory?

 

If the script name starts with capital letter "K", it is processed as a shutdown script, i.e. it is run when decreasing the runlevel, like when you're running a normal shutdown.

 

If the script name starts with capital letter "S", it is processed as a startup script, i.e. it is run when increasing the runlevel, like when booting up or transitioning from single user to multiuser mode.

 

If the script name starts with some other letter, it should not be processed at all.

 

The numbers after the first letter (three digits in HP-UX, two digits in many other unix-style systems) are used to force a particular execution order for the scripts: the scripts are actually executed in plain ASCII sort order. If your script requires networking to run, you should choose the numbers so that the script will run only after networking is started.

 

You should not be using "reboot" to reboot the system from full multiuser mode, as it will violently kill all running processes and bypass all configured shutdown scripts. If you're in single-user mode or have taken care to stop all application and daemon processes and unmount all non-essential filesystems, or the system is in so bad shape that a normal shutdown won't work, "reboot" can be acceptable. Running "reboot" in full multiuser mode is only very slightly better than crashing the system with the TOC button or the TC management processor command.

 

It seems your script is currently being run as a shutdown script, so it gets bypassed when you run "reboot" and it is not run at all when the system starts up. Running it as a startup script might be better.

MK
shameemsoft
Frequent Advisor

Re: Need to execute user defined script during reboot

Thanks Matti/Dennis for your response.

 

script is name is K003systeminfo & it is working in normal shutdown.

 

I need to collect the system output during reboot the system after patch bundle installation or when system crash. is it possible?

 

Regards

Shameem

Patrick Wallek
Honored Contributor

Re: Need to execute user defined script during reboot

If you are actually using the 'reboot' command, then no the script will not be run.

 

From the reboot (1m) man page:

 

WARNINGS

reboot does not invoke the shutdown scripts associated with subsystems to bring them down in a cautious manner.  See shutdown(1M).

 

Would it not make more sense to run the script as a startup script rather than a shutdown script?  That way it should always run, regardless of how the system was shutdown (shutdown vs. reboot).

Matti_Kurkela
Honored Contributor

Re: Need to execute user defined script during reboot

> I need to collect the system output during reboot the system after patch bundle installation or when system crash. is it possible?

 

Patch installation often requires a configuration step, which runs automatically after a reboot when the system is booting up. If you attempt to collect data in the shutdown phase, the collected data may indicate patches in incompletely-installed state (i.e. "installed" instead of "configured").The patch installation will be guaranteed to be completed only after the server has rebooted and completed the swconfig step (/sbin/rc2.d/S120swconfig) of the boot-up process.

 

There is an unlimited number of ways for the system to crash, but only a single way for the system to start up normally. A crashing system may be physically unable to run anything at all, so the only reliable point for data collection is when the system is booting up again.

 

My suggestion: change the script name to /sbin/rc2.d/S997systeminfo instead, so it will run while the system is starting up instead of while going down. Choosing a high number like 997 ensures that system services are up and running for the data collection (for example, swagentd will start up at /sbin/rc2.d/S870swagentd, so if your collection script needs swlist to work, it must run after that).

MK
Patrick Wallek
Honored Contributor

Re: Need to execute user defined script during reboot

I would change it to run with the scripts in run-level 3, probably as the last thing run.

 

/sbin/rc3.d/S997systeminfo