Operating System - HP-UX
1837488 Members
3580 Online
110117 Solutions
New Discussion

How to run a script when the system shuts down

 
Enrico Venturi
Super Advisor

How to run a script when the system shuts down

Hello colleagues,
I've a simple question for everyone is expert of HP-UX.
I'd like to run some emergency scripts when the system is suddenly shutdown, for instance when the power is discontinued, or even when the a shutdown is required by the "reboot" system command.
I knew that the system passes automatically through lower run levels, and it's possible to "link" some scripts to these run level transition; any more informations? is it true?

Thanks a lot
Enrico
9 REPLIES 9
RAC_1
Honored Contributor

Re: How to run a script when the system shuts down

What you know is true. If you want to particular scripts when box is shutdown/rebooted, you can put the scripts (kill scripts) at appropriate levels.

E.G. If you want o kill a certain daemon, (running in level 3) when shutdown/reboot is executed, you can put a script (kill script) in level 2 and link it to /sbin/init.d/xx script.

Also if you are worried about what will happen to system, when power goes off/has problems, you can set ups.conf file. (This comes with some UPS vendors)

Anil
There is no substitute to HARDWORK
Bernhard Mueller
Honored Contributor

Re: How to run a script when the system shuts down

Enrico,

start and stop scripts in HP-UX are in /sbin/init.d
in /sbin/rc2.d or /sbin/rc3.d you have S-tart links and K-ill links to that same script.

any k-linked script will be executed if you run shutdown command. *NOT* if you run reboot! Also not if you switch the system off, or reset it hard thorough GSP/MP

pls read
man rc

Regards,
Bernhard
Robert-Jan Goossens
Honored Contributor

Re: How to run a script when the system shuts down

Hi Enrico,

agree with above comments but you will need a ups in case of power problems. Ups software will shutdown your server.

Best regards,
Robert-Jan
Enrico Venturi
Super Advisor

Re: How to run a script when the system shuts down

As in your knowledge, can I use my Kill script to remote copy some small files in some neighbour hosts?
Fred Ruffet
Honored Contributor

Re: How to run a script when the system shuts down

In KXXscript links, XX specifies the order the scripts are run (one after the other). All you have to do, is to copy your files before network is down.

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Steve Steel
Honored Contributor

Re: How to run a script when the system shuts down

Hi

Info given is all good but since a power loss may take out your network you need to decide what you need.

If it is only a few small files then just run a cron job which checks for any of the files being changed since the last run and copies them.

You can use the newer function of find to check for changes

Steve Steel
If you want truly to understand something, try to change it. (Kurt Lewin)
Fred Ruffet
Honored Contributor

Re: How to run a script when the system shuts down

If your problem is to have your files even if server is down, you may consider using NFS or CIFS solution to replicate those files by cron on other servers.

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Muthukumar_5
Honored Contributor

Re: How to run a script when the system shuts down

We can make a script and put it on /sbin/rc.d/ directory with execution permission there.

When you are writing start / kill script then, you have to use full path to that binary as like,

/usr/bin/ls etc. Else use PATH variable there. It can not identify that PATH informations.

Try to select appropriate startup number as, Kxxx to make execute without getting problem because of related service killing there.

See more on man rc

HTH.

Easy to suggest when don't know about the problem!
Mike Patterson
Frequent Advisor

Re: How to run a script when the system shuts down

Hi, Enrico.

Perhaps, this is stating the obvious, but if the power is cut without a UPS, the system will simply shutoff with no orderly shutdown and no scripts will have time to run. Even with a UPS, some monitoring should page you on power failures to allow time for a manual or automated safe shutdown.

Regarding copying some files off before shutdown completes, yes, a kill rc script (as described above) could copy off some files. I'm just curious why would you want to do that? How will you use these files with the server shutdown - another system?

Thanks. - Mike