on 09-30-2011 10:02 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
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
[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
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.
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
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
Hello Subhash
No you would need to be on the same node
Run command from kernel directory
regards,
John Feely
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
11 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.