cancel
Showing results for 
Search instead for 
Did you mean: 

Windows script to shutdown sap after server reboot

Former Member
0 Kudos

Dear expetrs,

I have a SAP Instance installed on the same server where the SAP MC is. I want to have the instance to stop automatically when  the server reboot ( after installing updates files for example)

anybody know how I can do that?

My server runs windows server 2008 and the SAP system manager is v1.0 the MC is v.3.0

thx in advance

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

You can use this script if you run on Oracle, you have to adjust some parameters:


@ECHO OFF

setlocal

set THISHOST=<server>

set LOGFILE=%THISHOST%_stopsap_neu.log

set LOCAL=<SID>

set MYSID=<SID>

set SYSNUM=<SYSNR>

set CSYSNUM=<Central Services SYSNR>

set MYSAPPROGDIR=\\%THISHOST%\sapmnt\%MYSID%\SYS\exe\uc\NTAMD64

set MYNTREGCMD=%MYSAPPROGDIR%\ntreg2cmd %MYSID%

set MYDBSTOPCMD=%MYSAPPROGDIR%\brconnect -u / -c -f dbshut -f

if %USERNAME%=="SYSTEM" goto bad_user

tasklist | find "mmc.exe" > %LOGFILE%

if "0" == "%ERRORLEVEL%" taskkill /IM mmc.exe >> %LOGFILE%

echo %MYNTREGCMD%

%MYNTREGCMD%

call %MYSID%env.cmd

set /a MAXLOOPS=20

set /a LOOPS=0

:RESUME

set /a LOOPS=%LOOPS%+1

echo.

echo ###~~~~~~~~~~~~~~~~~~~~~~~~~~~~~###

echo Loop Nr.: %LOOPS%

set /a LOOPERR=0

sapcontrol -prot PIPE -nr %SYSNUM% -function StopSystem ALL >> %LOGFILE%

sapcontrol -prot PIPE -nr %SYSNUM% -function WaitforStopped 15 15 >> %LOGFILE%

sapcontrol -prot PIPE -nr %SYSNUM% -function GetProcessList >> %LOGFILE%

set /a RC=%ERRORLEVEL%

if "4" == "%RC%" set LOOPERR=0

if not "4" == "%RC%" set LOOPERR=1

if "0" == "%LOOPERR%" goto GO_ON

echo Waiting to stop...

if %LOOPS% GEQ %MAXLOOPS% goto CHKFAILED

if not "0" == "%LOOPERR%" goto RESUME

:CHKFAILED

echo.

echo Max. number of loops (%MAXLOOPS%) reached. Stop failed!

goto ENDE

:GO_ON

if not "%CSYSNUM%" == "%SYSNUM%" net stop SAP%MYSID%_%CSYSNUM% >> %LOGFILE%

net stop SAP%MYSID%_%SYSNUM% >> %LOGFILE%

echo Instance stopped, stopping DB!

echo %MYDBSTOPCMD%

%MYDBSTOPCMD%

goto ENDE

:bad_user

echo Please use SIDadm! >>\batcherr.err

:ENDE

Former Member
0 Kudos

Thanks Daniel,

Can you just show me where in the script above,you recuperate the shutdown event of server that triggers the sap service shutdown?

Former Member
0 Kudos

Somewhere in Windows, you can define scripts which should run before shutdown, I can post Screens tomorrow.

Former Member
0 Kudos

Ok , thanks

Former Member
0 Kudos
Former Member
0 Kudos

Thanks Daniel for your help.

Answers (0)