cancel
Showing results for 
Search instead for 
Did you mean: 

Shell script to start and stop sap system

Former Member
0 Kudos

Hi All,

Can anyone give me the shell script to stop and start the sap system?

I would be executing the following commands by using the below mentioned id's

<SID>adm : stopsap

  ora<SID> : lsnrctl stop

<SID>adm :saposcol -k

<SID>adm : cleanipc all remove

Where should i keep the particular script to get executed on a particular day at a particular time?

Any suggestions would be appreciated.

Best Regards,

Mano

  • SAP Managed Tags:

Accepted Solutions (0)

Answers (7)

Answers (7)

Former Member
0 Kudos

Thanks Abarajith and Matthias for your suggestions. I have executed the above mentioned script and stopped/started the systems.Now i am looking for the negative scenarios where any one of the command fails. I almost got the script.Looking for the right time to execute the script. Will let you know the commands, once it comes out successful.

Best Regards,

Mano Balaji

Former Member
0 Kudos

Did you use crontab?

Former Member
0 Kudos

Hi Abarjith,

Stuck up with other issues in system. Will check it and let u know.

Best Regards,

Mano Balaji

Former Member
0 Kudos

Hi Eimler,

Thanks. so we can capture the exit code in a variable and based on the exit code, we can proceed to stop the system.What if the listener control fails? is there any possibility to check that?

Best Regards,

Mano Balaji

Former Member
0 Kudos

Thanks Elimler. we have stopped and started the system with the help of this script. This executes correctly when all of the commands works as expected. In worst case scenario, is there any possibility to get back to the previous state if any one of the command fails within the script.

Best Regards,

Mano Balaji

willi_eimler
Contributor
0 Kudos

Hi Mano,

no. If the stopsap fails you have to analyze the problem. But instead of stopsap you could use

sapcontrol -nr 00 -prot NI_HTTP -function Shutdown

Then you can test the exitcode

EXITCODES
    0  Last webmethod call successful
    1  Last webmethod call failed, invalid parameter
    2  StartWait, StopWait, WaitforStarted, WaitforStopped, RestartServiceWait
       timed out
    3  GetProcessList succeeded, all processes running correctly
    4  GetProcessList succeeded, all processes stopped

And if it is not equal 0 you can stop the script and send a mail with sendmail.


Best regards

Willi Eimler

Former Member
0 Kudos

Hello,

Please use crontab to schedule your script periodically.

1.prepare your script (su - sidadm & orasid is must) as every one mentioned above.

2.log in as "root" in the host

3. command "crontab -e"

4. crontab file will be opened.you can edit crontab as you do in vieditor (i-insert then insert the following value)in the last line

#comment for your script.

0 0 * * 0 su - sidadm stopsap r3 <DIhost>

5 0 * * 0 su - sidadm  stopsap r3 <CIHOST>

10 0 * * 0 su - orasid lsnrctl stop <LISTENER_NAME>

15 0 * * 0 su - sidadm stopdb

20 0 * * 0 su - sidadmcleanipc all remove

25 0 * * 0 su - sidadm startdb

30 0 * * 0  su - orasid start lsnrctl <LISTENER_NAME>

35 0 * * 0 su - sidadm startsap r3 <CIHOST>

40 0 * * 0 su - sidadm startsap <DIHOST>

then save it by :wq

Note: "0 0 * * 0" (every week Sunday at 12:00 AM  all the year, All the month it will run)is given for weekly basis. you can refer the following and can understand how to give convenient time intervals as per your requirement.(the time values without space and the command should be separated by a space)

MinuteHourDayofMonthMonthDay of weekCommand
(0-59)(0-23)(1-31)(1-12orJan-Dec)(0-6) or (Sun-Sat)

Regards,

Abarajith V

Former Member
0 Kudos

Hi,

It is not the best way to schedule every single command in the crontab..

create one file like Willi suggested and add this file to the crontab.

Best regards

Matthias

Former Member
0 Kudos

Matthias,

It is possible but we need to insert sleep inside the commands. Also su - things wont work that properly. So I suggested individual.

Regards

AV

Former Member
0 Kudos

Hi Eimler,

I have written the script to startsap. Script executes the commands from <sid>adm properly.Initially it starts the saposcol.

But when it comes to ora<sid>, it is getting interupted at the line showing lsnrctl>.

Then i have to manually type "start" to start the listener control and then type "exit" to exit from listener control.Then it automatically executes startsap.

One more thing, i haven't included double quotes("") while executing the commands in script.'

I have given just su - <orasid> -c lsnrctl start.

Is it necessary to include double quotes?

Best Regards,

Mano Balaji

willi_eimler
Contributor
0 Kudos

Dear Mano,

yes.

Best regards

Willi Eimler

Former Member
0 Kudos

Hi Eilmer,

Thanks a lot for your suggestion. I will try out this thing and let you know the result.

Best Regards,

Mano Balaji M

Former Member
0 Kudos

Thanks Eirnler for your suggestion.I like to get this script executed automatically at a particular point of time.Can u give me the shell script for that? Thanks in advance.

Best Regards,

Mano Balaji M

willi_eimler
Contributor
0 Kudos

Hi Mano,

Make the following scrtipt e.g. /usr/sap/MySAPscripts/StopMySAP

#!/bin/sh

# StopMySAP : Name of Script

su - <sidadm> -c "stopsap"

su - <orasid> -c "lsnrctl stop"

su - <sidadm> -c "saposcol -k"

su - <sidadm> -c "cleanipc all remove"

And then put /usr/sap/MySAPscripts/StopMySAP into crontab

look at:

http://www.adminschoice.com/crontab-quick-reference/

or

http://www.computerhope.com/unix/ucrontab.htm

Best regards

Willi Eimler

willi_eimler
Contributor
0 Kudos
Hi Mano,
try this (not tested) script as root:
#!/bin/sh
su - <sidadm> -c "stopsap"
su - <orasid> -c "lsnrctl stop"
su - <sidadm> -c "saposcol -k"
su - <sidadm> -c "cleanipc all remove"
You could put this job in the crontab.

Best regards

Willi Eimler