cancel
Showing results for 
Search instead for 
Did you mean: 

Script to Shutodwn SAP

former_member185031
Active Contributor
0 Kudos

Hi,

I am working on the Script to shut down and start up SAP application through Batch file on Windows. I am succesfully able to execute my script. But my problem is i have 2 Node. On Node A Central instance is running and on Node B Application server is running. So right now what i am doing i am running to file on Node a and Node b to stop and start. Is there any possibility that i can shut down the Node b from my Central instance it self through script. for example this is my script and i am changing the host name and other details and running from Node b also to shut down.

echo off
cd \batchfile
CALL D:\usr\sap\NSP\SYS\exe\uc\NTI386\stopsap name=DP1 nr=00 SAPDIAHOST=sapdev >>  c:\batchfile\shutlog.txt
cd \batchfile
CALL NET stop "SAPHostControl" >> c:\batchfile\stoplog.txt
CALL NET stop "SAPHostExec" >> c:\batchfile\stoplog.txt
CALL NET stop "SAPDP1_00" >> c:\batchfile\stoplog.txt

Thanks

Subhash

Accepted Solutions (1)

Accepted Solutions (1)

former_member189546
Active Contributor
0 Kudos

hello,

Best to use sapcontrol newer than stopsap

For instance

'sapcontrol -nr <instance nr.> -function Stop'

Check the options for sapcontrol

<instance nr.> stands for instance number

regards,

John Feely

former_member185031
Active Contributor
0 Kudos

Thanks John for your reply. I will check the options on sapcontrol but are you aware that i can use sapcontrol from node a to shut down the app server which is running on node b.

Thanks

Subhash

Former Member
0 Kudos

Hi subhash,

Were you able to get the sapcontrol to work? can you share?

Thanks,

Ali

Answers (3)

Answers (3)

former_member224961
Discoverer
0 Kudos

To start or stop sap system Create two Batch files as following:


1 - StartSap.bat

<Drive>:\usr\sap\<SID>\DVEBMGS00\exe\startsap name=SID nr=01 SAPDIAHOST=<Host name>

<Drive>:\usr\sap\<SID>\DVEBMGS00\exe\startsap name=SRD nr=00 SAPDIAHOST=<Host Name>

Example:

c:\usr\sap\ERM\DVEBMGS00\exe\startsap name=SID nr=01 SAPDIAHOST=windows1Q002

c:\usr\sap\ERM\DVEBMGS00\exe\startsap name=SRD nr=00 SAPDIAHOST=windows1Q002

2 - StopSap.bat

<Drive>:\usr\sap\<SID>\DVEBMGS00\exe\stopsap name=SID nr=01 SAPDIAHOST=<Host name>

<Drive>:\usr\sap\<SID>\DVEBMGS00\exe\stopsap name=SRD nr=00 SAPDIAHOST=<Host Name>

Example:

c:\usr\sap\ERM\DVEBMGS00\exe\ stopsap name=SID nr=01 SAPDIAHOST=windows1Q002

c:\usr\sap\ERM\DVEBMGS00\exe\ stopsap name=SRD nr=00 SAPDIAHOST=windows1Q002



note : nr=" you need add row for all instants in yellow color"

sandeepkarnati
Participant
0 Kudos

Hello Kamal,

Thank you for the input.

lets say i have 3 steps in my cycle 1)stop or start instances 2)update system center about system status 3) send an email.

from the above script how to validate instances are up and running or instances are down before going to second step.

does your script works for java and dual stack sytems...i mean does that script works to bring jstart.exe  process online?

Former Member
0 Kudos

Hi,

First: I strongly recommend you to use powershell instead of bloody old and stupid cmd.exe (Batch files). With powershell it is very easy to do really complicated things where you would break your fingers trying to do it on cmd.exe.

Second: use sapcontrol.exe instead of deprecated stopsap script - it is part of the every kernel and instance directory (/usr/sap/SID/SYS/exe/uc/ntamd64 or /usr/sap/SID/DVEBMGSxx/exe) and has a very rich functionality.

For online help information just run it in a cmd.exe without parameters

sapcontrol.exe is also able to work remotely:

This command will stop all instances of a system in the right order:

/usr/sap/SID/DVEBMGS01/exe/sapcontrol.exe -prot PIPE -nr 01 -function StopSystem ALL

But you can also stop the system instance by instance.

Stopping the services can be done using powershell commands:

stop-service SAP*
will stop all services whoes name starts with SAP.

you can use sc.exe which is able to control services remotely.

sc.exe <server> [command] [service name]

For stopping SAPHostControl on computer nodeB:
     sc.exe nodeB stop SAPHostControl

A very interesting feature of powershell is powershell remoting.
It has features similar to ssh - so you can execute code on a remote computer.

Here you can run a single command on several computers:
invoke-command -computer nodeA,nodeB {stop-service SAPSID_00}

This will stop the Service SAPxxx_01 on the local computer, the SID is not needed, because the number has to be unique on a host).

C:/usr/sap/SID/DVEBMGS01/exe/sapcontrol.exe -prot PIPE -nr 01 -function StopService

This will stop the Service SAPxxx_01 on the remote computer nodeB, the SID is not needed, because the number has to be unique on a host).

C:/usr/sap/SID/DVEBMGS01/exe/sapcontrol.exe -prot PIPE -nr 01 -function StopService -hostname nodeB


Third. SAPHostExec Service depends on SAPHostControl. Starting/Stopping SAPHostControl will also start/stop SAPHostExec.

Forth:

Stopping an SAP-Windows-Service will also shutdown it's instance.

Don't waste your time writing batch scripts - use powershell!

regards

Peter

Former Member
0 Kudos

Hello Peter,

I'm just writing on a script to start/stop/... a sap system but unfortunately I haven't found a way to dynamicall read the instance number of the sap system which has to be started/stoped via my script.

Is there any way in windows to get the instance number(s) of a SAP system (without cutting out of the file system structure)?

Many thanks

Roland

Former Member
0 Kudos

Hi Roland,

very easy:

First of all use powershell:

Get the SIDs installed on a computer:


get-service SAP???_?? | %{$_.name.substring(3,3)}

Get the system numbers of installed SAP Systems on a computer:


get-service SAP???_?? | %{$_.name.substring(7,2)}

Former Member
0 Kudos

Hi Peter,

ahh very nice solution.

Meanwhile I wrote the following to get the instance nr via filesystem

[string]$instance = ls (join-path ${sapmnt} ${SID}) | Select-String -List "DVEBM","J"

$nr = $instance.Substring(($instance.Length-2),2)

Maybe also helpful, especially if no system/service is running and you need to get the infos.

Thanks!

Roland

Former Member
0 Kudos

[string]$instance = ls (join-path ${sapmnt} ${SID}) | Select-String -List "DVEBM","J"

$nr = $instance.Substring(($instance.Length-2),2)

Please be aware that we also have SCS/ASCS/Dialog/Gateway instances which will not be captured by "DVEBM","J"


Maybe also helpful, especially if no system/service is running and you need to get the infos.


Argument 1: the service does not need to be started in order to get listed in get-service cmdlet.

Argument 2: an installation not using Windows Services for an SAP is not supported by SAP.


By the way, if you are just interessted in running services:


get-service sap* | where status -eq "Running" ...

(will run on Windows Server 2012 R2 and following. On older powershell versions the where-object looks slightly different)


regards


Peter



sandeepkarnati
Participant
0 Kudos

Hello Peter,

I am using powershell to stop and start the instances using sapcontrol.exe.so below is the code to stop the instances.

$a= get-service SAP???_?? | %{$_.name.substring(7,2)} #Pulling all the instance numbers into array

for ($i=0; $i -lt $a.length; $i++) {

  # $a[$i]

   ./sapcontrol -user <user-name> <password>  -nr $a[$i] -function Stop

}

so i have three instance in the array $a[i] ie:97,00,01 ,my requirement is

1)To stop the 97 first and make sure 97 is stopped i mean wait untill 97 is stopped and then stop 00 again make sure 00 is stopped then stop 01.

2) As you mentioned above to stop services using stop-service SAP*,could you please elaborate how to stop SAP services.

j_bayrhammer
Participant
0 Kudos

Hello Peter,

is there a note which contains the recommendation to use sapcontrol command instead of stopsap?

We still use stopsap and determine problems, because stopsap doesn't stop the sapcontrol-Service.

Regards

Julia

j_bayrhammer
Participant
0 Kudos

Found note myself:

1763593 - Starting and stopping SAP system instances - startsap/stopsap are deprecated

Regards,

Julia

Former Member
0 Kudos

you should also consider to have a look at the

-function StopWait   / StartWait

!

-function Start / Stop will only initiate this action and will immediatly return. It will not wait until the instance is completely stopped. Using StartWait/StopWait you can stop and wait to a timeout until the instance comes down.

Meanwhile - in newer versions of sapcontrol - there are also functions like StopSystem / StartSystem which will Start and Stop all instances of a SAP System in the correct order.

regards

Peter

j_bayrhammer
Participant
0 Kudos

Hello Peter,

how is it possible to stop database with that sapcontrol-command?

stopsap stops complete system, stopsap r3 stops only instance.

Is there an option with sapcontrol? And if not should we use 'stopsap db' then?

Why use then sapcontrol command?

Regards

Julia

Former Member
0 Kudos

stopsap db was never implemented on Windows in the past. Therefore you have no possiblilty to use stopsap DB on Windows. You will have to call DB-Vendor specific programs/commands in order to stop the database.

There is no sapcontrol -function StopDB or whatever it would be named for several reasons.

- stopping the database with the SAP system was often performed to create an offline backup of the database. This changed. Today everybody is performing online backups.

- we have a lot of huge installations where the DB is running just like a service on a different box. Databases are administrated by a different group of persons (DB-Administrators) and they don't like an SAP System Landscape Administrator to stop the database when shutting down an SAP System.

- remote database access from other SAP systems would fail.

. High Avalable database configurations do need a different administrator interface to use

- in some databases (like SQL-Server) you normally can't stop a single instance. Stopping the database would stop all database instances.

- in MCOD configurations (several SAP Systems use one database instance to store their data in.

- Double Stack installations

stopsap db was a very old functionality which never was adopted to the environments listed above.

When sapcontrol was designed it was decided to keep shutdown out of the scope.

kind regards

Peter

j_bayrhammer
Participant
0 Kudos

Hello Peter,

thank your for your detailed answer.

We're on UNIX and are still stopping systems using startsap / stopsap -r3|db and are doing offline backups.

Regards,

Julia

j_bayrhammer
Participant
0 Kudos

Hello,

I opened an incident at SAP OSS marketplace.

They recommend to use sapdbctrl or startdb/stopdb scripts from kernel directory instead.

Regards,

Julia

former_member189546
Active Contributor
0 Kudos

Hello Subhash

No you would need to be on the same node

Run command from kernel directory

regards,

John Feely