cancel
Showing results for 
Search instead for 
Did you mean: 

How to start SAP System using a script on Windows.

Former Member
0 Kudos

Hi,

we have a sap system running on windows.

Iam not good at prgramming, iam looking for a small script which first starts Oracle and then SAP system on windows machine.

It should look something like this:

Check if Oracle listener process is down

if yes

(

start the oracle listener

5 seconds pause

start the Oracle DB

5 seconds pause

start the sap

)

if no

(

do nothing

)

Please help.

Many thanks,

Mohan.

Accepted Solutions (1)

Accepted Solutions (1)

former_member182034
Active Contributor
0 Kudos

hi Krishna,

As per your requirement. first You can start Oracle then SAP in a sequence(oracle, SAP).

For Start Oracle:

Please create a file with name startup.sql and put this text startup

now make a batch file with name StartOracle.bat and put the following text.

sqlplus /@SID as sysdba @drive:\Startup.sql

For Start SAP:

Please make a batch file with name StartSAP.bat and put following text as per your installation drive.

usr\sap\SID\DVEMGS00\exe\startup name=SID nr=00 sapdiahost=Hostname


now schedule the both batch files(StartOracle.bat, StartSAP.bat ) via

Start --> Administrative Tools --> Task Scheduler

FYI..: whenever you start the SAP via SAPMMC. first start the oracle and start the sap ecc.

Regards,

Former Member
0 Kudos

Hi Billy & Abdul,

based on your tips, i created this code but somehow it is not working. Where am i going wrong? The code is based on my logic above:

net Start|find /i "OracleEFB11203TNSListener">nul

If errorlevel 1

(

Net start "OracleEFB11203TNSListener";

sqlplus "/ as sysdba" ;

startup open;

exit;

startsap name=EFB nr=00 SAPDIAHOST=vm0123;

)

else

(

echo Processes are running

)

Regards,

Mohan.

Former Member
0 Kudos

my first advise is:

  •     do not use cmd.exe (.cmd, .bat -files) for scripting. Use Powershell instead. it is much more strait forward, better to control...

You need to pay attention that starting a service will first start the service process which is normally in "start pending" mode. If the service reaches the status "running" it is operational and you can work with.

So be prepared to listen to the current status before performing the next step.

In terms of Oracle the database consists of at least two processes:

  1. the database process itself (started via Windows Server OracleServiceSID
  2. and a listener

The listener is needed to allow remote connections (using tcpip or named pipe sockets. SAP Systems perform a remote connection to the database).

You can start the listener any time without starting the database.

The database itself consist of two different services:

  1. the database process (oracle.exe started via the Windows Server OracleServiceSID)
  2. and the database instance (additional threads in oracle.exe after the database has been started)

The database instance can be started when starting the (Windows) database service. Thats a question of the configuration of the service (run oradim for more information).

In powershell:

Start-Service "OracleServiceXXX"

Start-Service "Oracle*Listener"  #yeah Start-Service supports Wildcards!!

# be sure that you have defined ORACLE_SID as environment variable!!!

# furthermore your user account needs to be in the ORA_DBA or ORA_SID_DBA operating system group

$env:ORACLE_SID="PRD"

sqlplus /nolog

connect / as sysdba

startup

exit

# now we start the sap instance. Do no longer use sapstart/startsap

sapcontrol.exe -prot PIPE -nr 00 -function Start

that's it

regards

Peter

Former Member
0 Kudos

if running things in the Windows Scheduler use <sid>adm as account.

otherwise you will miss group memberships and environment variables which are required for the right configuration of the tools.

bxiv
Active Contributor
0 Kudos

You need to create If / Then statements and based on the conditions met will run the execution.

If oracle.service.1 = down then start oracle.service.1

or

If oracle.process.1 = down then start oracle.service.1

You are going to have problems trying to start services that are already running and return odd values if you do not first capture the status of the services/processes.

Answers (2)

Answers (2)

ashish_vikas
Active Contributor
0 Kudos

Chek this wiki.. you will very happy to start with this.

http://wiki.scn.sap.com/wiki/pages/viewpage.action?pageId=198738223

best regards

ashish

Former Member
0 Kudos

Dear Ashish,

thanks for the link. I have managed to write the code on my own:

@echo off

net Start|find /i "OracleEFB11203TNSListener" >NUL

IF ERRORLEVEL 1 (

ECHO NOT Running.

net start OracleEFB11203TNSListener

sqlplus "/ as sysdba" @D:\scripts\startdb.sql

startsap name=EFB nr=00 SAPDIAHOST=vmbn0236

    ) ELSE (

ECHO Running.

)

pause;

In the startdb.sql , i wrote startup open; exit;

Thanks to everybody,

Mohan.

bxiv
Active Contributor
0 Kudos

A batch file should accomplish this just leverage the 'sc' command:

sc start oracle.service.1

ping ip.add.re.ss

sc start oracle.service.2

ping ip.add.re.ss

sc start SAP


This doesn't include service/process checking, but you can leverage something like pslist to check on a process and depending on the exit code take action.