Operating System - HP-UX
1751840 Members
5232 Online
108782 Solutions
New Discussion

How to remotely stop and start a windows service from a UNIX shell script.

 
EU-Admins-UNIX
Regular Advisor

How to remotely stop and start a windows service from a UNIX shell script.

Hi

 

I have been tasked to carry out a dump and restore of an oracle expdp file from live to test.  I am hoping to automate this via a script.  One hurdle I need to overcome is killing of an Application service on 3 load balanced windows servers, lets call them app1, app2 and app3, before I can drop the oracle user.

 

Is there any way of doing this?

 

Regards

 

Tariq

5 REPLIES 5
EU-Admins-UNIX
Regular Advisor

Re: How to remotely stop and start a windows service from a UNIX shell script.

(Just replaying to myself so I can get email updates)

Ken Grabowski
Respected Contributor

Re: How to remotely stop and start a windows service from a UNIX shell script.

This type of process is often handled by backup software agents or a cross platform scheduler.  With out one of those, your next choice might be to put a UNIX runtime application like MKS Toolkit and set it up to allow an SSH user connection. Then you could run scripts on windows from remote UNIX servers. I have done similar things with all three of those approaches. The first two are preferable, the last one can be messy.

 

Why do you need to control it from UNIX?  Windows scheduler could probably do the same thing on the Windows host.

EU-Admins-UNIX
Regular Advisor

Re: How to remotely stop and start a windows service from a UNIX shell script.

Ken

 

Ideally I would like to have one a one script solution to (crudely):

 

kill the windows process

run the oracle sqlplus processing, ie dropping users, granting permissions

run the import from the shell

start the windows service

Steven Schweda
Honored Contributor

Re: How to remotely stop and start a windows service from a UNIX shell script.

 
Ken Grabowski
Respected Contributor

Re: How to remotely stop and start a windows service from a UNIX shell script.

Well if crudely is how you want to go  then the UNIX on Windows approach could work for you. I have done it. But you have to build a lot of error testing into your scripts.  There are commercial products with support like MKS UNIX on Windows and also free unsupported ones like cygwin. I always recommend using the commercial applications that can be purchased with support. Then it's a matter of setting up the Windows system to allow the remote login of users via SSH and building ksh scripts on the Windows side to stop and another to start your windows services.

 

Remember you are installing a UNIX service on Windows. They consume resources and have to be monitored.  In the shops I've worked where we needed to run ksh on Windows hosts, we dedicated the Windows servers to that purpose. Only those Windows services that where the targets of those scripts lived on the same servers.  Even then, they sometimes created problems for each other.

 

Your HP-UX side scripts will have to execute the remote scripts using SSH, the same way you would do it for UNIX to UNIX.  The trick, and the messy side of it is working out ways to determine the success or failure of the remote scripts before going ahead with your sqlplus processes. Having the Windows scripts put flag files back on the UNIX system is one way to go. Your UNIX script can launch the remote script then loop until it gets a flag file to examine. But don't forget to put a time out into your loop. Failure could also be the windows side not being able to write the flag file.

 

A couple of thoughts on other alternatives:

1) Use windows scheduler to bring down the app and then restart it later at a fix point in time. Schedule your UNIX scripts to run in between those two jobs.

2) Use sqlplus to disconnect the Windows application user and block reconnection until the Oracle processes are complete. If the Windows process needs to be restarted before it will reconnect to Oracle, then use windows scheduler to run a net servicename restart command (not sure about the syntax there) well after when your Oracle/UNIX process should be done.

 

While the UNIX script run remote on windows can be done, without a cross platform job scheduler it's hard to control the flow and determine if the windows steps have been successful.  I would try alternatives first and leave remotely controlled scripting for the last resort.