Saturday, July 12, 2008

Raquel Darrian On Fire Free

Start / Shutdown SAP

several months in the company we are dealing with SAP, ERP homonymous German house SAP AG. New world for us used to working within Microsoft that required much time devoted to the study by the team impegnatp in the development and customization of the solution that revolves around SAP technology.
Especially for the undersigned (Developer paid in class 'system and infrastructure) and' was a challenge to be able to automate the launching and switching services mmc otherwise bootable cross the main administration of the product (and then manually and is therefore not very comfortable). As we all know those who for one reason or another, have to turn off SAP ('cause maybe you should make a backup of virtual machine on which' installed, or because 'should make a very simple upgrade of Microsoft Windows) can understand the need 'of a system to automate the on / off the various instances of the product, since' the SAP database seems to be very sensitive (according to what was said by the technician who installed the product at our company) and, you know ... susceptible to a shutdown or restart Windows without taking the necessary precautions (shutdown of instances, to be precise). Well studying

a bit 'SAP documentation (very poor in terms of available commands for the shell), I managed to find a command that runs from command shell, switch off and allow the instance of SAP desired sapcontrol.exe .

Here the command to use for the shutdown of an instance

D: \\ usr \\ sap \\ DEV \\ DVEBMGS02 \\ exe \\ sapcontrol.exe -user-format-function Shutdown script-nr

and the command to turn on

D: \\ usr \\ sap \\ DEV \\ DVEBMGS02 \\ exe \\ sapcontrol.exe -user-format-function script Start-nr

to complete the automatic need only verify that the instance has stopped and then reboot. To this end I wrote a script in vbscript that waits for the selected instance off before finishing its execution:


Option Explicit Dim


September WSO WSO = CreateObject ("WScript.Shell") Dim

InstanceNumber
InstanceNumber = WScript.Arguments (0) Dim

ServiceAccount
ServiceAccount = WScript.Arguments (1)

Dim Password = Password
WScript.Arguments (2) Dim Status

, ExitCode

ExitCode = Shutdown (InstanceNumber, ServiceAccount , Password)

if ExitCode = 0 Then Dim
Stopped
Stopped = false

do while Not Stopped
Status = GetStatus( InstanceNumber, ServiceAccount, Password)

if Status = "Stopped" Then
Stopped = true
elseif Status = "NotFound" then
exit Do
else
WScript.Sleep 5000
end if

Loop

WScript.StdOut.WriteLine Status

else

WScript.StdOut.WriteLine "Error Shutting down " & InstanceNumber

end if

set wso = nothing


function Shutdown( instanceNumber, serviceAccount, password)
Dim oExec

set oExec = wso.Exec( "D:\usr\sap\DEV\DVEBMGS02\exe\sapcontrol.exe -user " & service Account & " " & password & " -function GetProcessList -format script -nr " & instanceNumber)

do while oEXec.Status = 0
WScript.Sleep 100
Loop

Shutdown = oExec.ExitCode
set oExec = nothing
end function

function GetStatus( instanceNumber, serviceAccount, password)
Dim Line, Result
Dim oExec

Result = "NotFound"

set oExec = wso.Exec( "D:\usr\sap\DEV\DVEBMGS02\exe\sapcontrol.exe -user " & Account Service & "" & password & "GetProcessList-format-function-nr script" & instanceNumber)

oEXec.Status = 0 do while

WScript.Sleep 100 Loop Do While Not

oExec.StdOut. AtEndOfStream
Line = oExec.StdOut.ReadLine

if InStr (Line, "0 textstatus") then
Result = Right (Line, Len (Line) - 14)
Exit do end if


Loop

GetStatus = Result

September oExec

= nothing end function


That 's all, I hope the script will be useful as well' as is' for myself. Until next time. :)