cancel
Showing results for 
Search instead for 
Did you mean: 

Trying to use the SAPINFO.exe in .bat File

Former Member
0 Kudos

Hello World,

So i am trying the command prompt to check for all If my SAP systems on windows servers are up and running or not,

so i made SAPSYSTEMS.txt file contain  the hostname for all my sap systems each in a line,

then i made checkrfc.bat file with the code bellow :

@echo off

rem ======================================================================

rem Script: CheckRFC.BAT

rem It uses SAPINFO from the RFC-SDK (SAPGUI) to check an RFC destination.

rem It needs two parameters: 1. Hostname 2. Instance Number

rem A ping is sent to the host. If successful an RFC check is carried out.

rem ======================================================================

if “%2″==”" goto NoParameter

echo Pinging %1 …

ping %1 -n 2 | find /i “reply” >nul && goto CheckRFC

echo System does not exist on the network! & goto Bye

:CheckRFC

sapinfo ashost=%1 sysnr=%2 & if errorlevel 1 goto System_Down

echo —————————

echo System is up. RFC checks OK!

echo —————————

goto Bye

:System_Down

echo —————

echo System is down!

echo —————

goto Bye

:NoParameter

echo ———————————————

echo Syntax: checkrfc “hostname” “instance number”

echo Example: checkrfc mydev 00

echo ———————————————

:Bye

then i made checkallrfc.bat file with the code bellow :

FOR /F %%i in (SAPsystems.txt) do call checkrfc %%i 00

i didnt find the SAPINFO.exe in the SAP gui dir. so i downloaded one from the net with size 36KB and placed in in the same folder on Desktop that contain the .bat and .txt file.

now when i run checkallrfc.bat it opens a command windows and automaticlly close it in less than 2 sec

also if i try to run the checkrfc.bat file same thing happen.

can anyone help me to idintify this problem and its cause ?

Thanks In Advance

Regards.

Ahmed Salam.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Dear All , Thanks For your support

i have come to develop more simple CMD script to check for the SAP systems on windows platform

i even added a feature to the script to send mail to you with the status of the system. P.s REM means a remark you dont have to write it in your batch file

Prerequisites:

---------------------

-Download  SAPINFO.exe from http://www.filewatcher.com/m/sapinfo.exe.36935-0.html and place it is the dir where you will create the batch file.

- if you have Business Object SAP System you will need to download and install Nmap from http://nmap.org/

Code For Batch File:

-------------------------------

@echo off

rem we use sapinfo to check for the instance of the sap system and if its up the error lvl is 0 and if it is down it returns 1

rem this can work for abap servers or double stack servers but for java only stack servers we use other mechanism

rem in order to send mails you cant use .bat or .cmd file you have to use .vbs file

rem thankfully we have the "cscript " command that allow us to call a vbs file within bat file

rem so the bellow code is we sapinfo with the hostname or ip and the main instance no. of the system

rem if it returns one we call the downmail.vbs file cause that mean it have an error

rem else  it returns 0 we call the upmail.vbs file cause it means it up and running

sapinfo ashost=HostnameORip sysnr=instanseNoOf Abap System & if errorlevel 1 ( cscript "<dir to your Downmail.vbs File" ) else ( cscript "dir to your upmail.vbs File" )

// the above code if the all the ABAP SAP Systems Not java Systems Like Enterprise portal

//you can repeat the above line over and over in the batch file for all your systems but note that

all of the above code should be in the same line for each system

// also each system should had its own DOWN and UP mail.vbs files to be accurate

E.G

sapinfo ashost=10.2.6.100 sysnr=00 & if errorlevel 1 ( cscript "D:\soldownmail.vbs" ) else ( cscript "D:\solupmail.vbs" )

Now the code for Java Only System E.g EPortal Read The Remarks carefully

------------------------------------------------------------------------------------------------------------------

rem below is the code for java only stack systems, it also uses the sapifno Technic

rem in hear we call the instance for java which is by default 01

rem if the server is up or down it returns an error cause java only servers doesn't have rfc configuration to them

rem however sapinfo sense the occurrence of a SAP GATEWAY and stats the FQN of the server its on

rem so when it sense the occurrence of the SAP GATEWAY it returns the FQN of the server

rem so we insert the output in a txt file and check for the server hostname on it if it find it it return error level 0

rem that means its up and if it returns 1 so no hostname was returned cause it didn't sense the sap-gateway which means the system is down

rem e.g in below the hostname is EPPRO and i have tested by putting the system down and it didn't return the FQN of the host

rem last step we delete the txt file cause it have no use anymore

rem Java Instance No. is usually 01 Unless you changed it

sapinfo ashost=hostnameORip sysnr=Java instanceNo.  > D:\1.txt

find /c /i "EPPRO" D:\1.txt

if errorlevel 1 ( cscript "D:\EPPRODownmail.vbs" ) else ( cscript "D:t\EPPROupmail.vbs" )

del D:\1.txt

// This Technic is not official its a work around i made up cause the only way to check for java

only systems from CMD is Jcomn and it need interaction you cant use it as an automatic batch job

// Also you can repeat it over and over in the same batch file and make both codes for ABAP and JAVA Only systems in the same batch file it works fine

Now If you have a 3rd party System like SAP Business Object SBOP you will have to download nmap as i stated above

// SBOP uses a Web Server like Tomcat ,, this web server have its own port that you define while installing It is most commonly 8080 so when need to ping this port some how not the host cause the host could be up but the web server is down , this cant be achieved by the normal Ping command

so we use Nmap

Here is the code :

----------------------------

nmap -p8080 IPADDRESS  >D:\2.txt

find /c /i "CLOSED" D:\2.txt

if errorlevel 1 ( cscript "D:\SBOPupmail.vbs" ) else ( cscript "D:\SBOPdownmail.vbs" )

del D:\2.txt

//Nmap returns (web server is down case :

Nmap scan report for IPADDRESS

Host is up (0.0071s latency).

PORT       STATE     SERVICE

8080/tcp    closed      unknown

Nmap done: 1 IP address (1 host up) scanned in 18.07 seconds

// so we look for CLOSED if it is absent in the txt file that means its up and running cause when it is up and running the state is open so you can either check for closed or open in my case i choose closed

Nmap scan report for IPADDRESS

Host is up (0.0071s latency).

PORT       STATE     SERVICE

8080/tcp    open      http

The Mail.vbs Code :

------------------------------

Set objMail = CreateObject("CDO.Message")

Set objConf = CreateObject("CDO.Configuration")

Set objFlds = objConf.Fields

objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2

objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "<SMTPName Or Ip>.DOMAN.com"

objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

'uncomment next three lines if you need to use SMTP Authorization

'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "<Username on the domain>"

'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "<password>"

'objFlds.Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1

objFlds.Update

objMail.Configuration = objConf

objMail.From = "<whatever_you_want@Bla.Bla>"

objMail.To = "<Your Mail>"

objMail.cc = "<Any mail or leave empty>"

objMail.Subject = "<Name of system>"

objMail.TextBody = "<Name : State>"

objMail.Send

Set objFlds = Nothing

Set objConf = Nothing

Set objMail = Nothing

// replace all that is between <> with its relevant

SAPROUTER check :

//you can add this code as well to your batch file to check for your sap router service

TASKLIST /S <host or ip>/U <username> /P <password>  /FI "imagename eq <name of the service and the extension>" /svc & if errorlevel 1 ( cscript "D:\SRDownmail.vbs" ) else ( cscript "D:\SRupmail.vbs" )


// remember all in the same line in the batch file otherwise you may get errors

//name of service is usually "saprouter.exe"

//username and password for an admin host user

------------------------------------------------------------------------------------------

And That's Every Thing it works great like a charm with me and saves me alot of time also makes me Pro-active by scheduling a task on windows to run the batch file every day before working hours by an hour and also i run a batch file that only sends mail if system is down every 1 hour

Feel Free to ask me for anything , Hope it helps

Regards,

Ahmed Salam.

Message was edited by: Ahmed Salam

Former Member
0 Kudos

Oh my God!!!!!!!!

Gents,

you should really give yourself and your productivity in writing scripts a chance and start having a look into powershell.

These Batch-File and VB-Script samples are horrible!

kind regards

Peter

former_member182034
Active Contributor
0 Kudos

hi Peter,

I think, Ahmed should have to create a blog/document of this activity because he have done a good job and try to explain in detail.

Regards,

Former Member
0 Kudos

Dear Peter,

I didn't understand wither this was an complement or an insult but i kinda felt it was more of an insult , However, i am greatly thankful for your interest in my discussion and if you didn't think that these scripts are good they are for me cause they solved what i was trying to do and works fine for us , i had an idea and somehow i made it live and i couldn't find other solution for it. maybe its not good for you but it is for me, and i posted for others maybe some one could benefit from it.

Thanks, Regards.

Ahmed Salam.

Former Member
0 Kudos

well ,

assuming that the most people are meanwhile using Windows Server 2008 or newer - they have the possibility to use current powershell versions (3.0 or 4.0 - Windows Server 2003 only supports 2.0).

But event with the limited functionality of powershell 1.0 and 2.0 you can do most of the stuff more reliable, easier to read, easier to understand and hence easier to maintain.

with powershell most things are much easier to implement than using VBS or cmd.exe.

Just as an expample: sending an e-mail:

just use:


send-mail -to recepient@somewhere.com -subject "an easy example" -body "Hi all - this is just an example" -attachments c:\temp\attachment.txt -smtpserver mail.yourcompany.com -from sender@somwhere.com

one command - not a separate script...

Or checking whether a service is running on the current computer:

if ((get-service "SAPOSCOL" 2>$null).status -eq "Running")

{

     "oh -it is up and running"

}

or on a remote computer:

if ((get-wmiobject win32_service -computer "remotebox" | where {$_.name -eq "SAPOSCOL"}).State -eq "Running") {

     "do something else"

}

But these are only two of much more possible methods to perform these actions (in addition we have get-service supports -computer switch, powershell remoting...)

As of Version 2.0 you have script debugging (ISE) - a great help for developing the scripts.

Security sensitive information can be provided using the credential mechanism, which not only allows the secure handling of account information in the script itself, but also  to store credentials in a manner not visible to anybody (instead to provide it in clear text in the batch file when using tasklist /s).

Especially in terms of security powershell is much - much safer - including digital signing of scripts and preventing execution of unsigned scripts via group policy in a domain.

So please do not understand my comment as a complement or insult!

I welcome your contribution to this community and thank you for that.

But, if I detect recommendations or examples where you need to provide username and password in clear text - well, then I get headaches and then personal need to put some comment on it:
Batchfiles are a nice historical and very primitive instrument. We are now in 2014 and no longer in NT 3.5 (1995). Today, there are more accurate tools for performing what you are trying to do.

regards

Peter

Former Member
0 Kudos

Dear Peter,

Thanks You for your recommendation and i will try Power Shell  tool , i didn't know a way to do this task but CMD batch files so i went through it i didnt know that power shell could do the same , however can i use it to check if the SAP systems are up or not ?

Regards

Ahmed Salam

Former Member
0 Kudos

of course!

listen to the SAP on Window Blog.

I will add an example to it how to detect a system is working and how to access detailed information with powershell.

regards

Peter

Former Member
0 Kudos

Dear Peter,

Please provide the link for the SAP on window blog

i searched for it but i get over 40k results

Thanks

Matt_Fraser
Active Contributor
0 Kudos

You can find it by going to the 'SAP on Microsoft Windows' space in SCN, select 'Content', and on the left is a link under 'View the blog.'

Regards,

Matt

Former Member
0 Kudos

Dear,

I checked it and i couldn't find anything even remotely close to what i made with normal CMD

Regards

Former Member
0 Kudos

Hi Peter,


Do you have plans to post a PowerShell example of what Ahmed was trying to accomplish?  I think this code would be particularly helpful in determining system status as part of an automated patch process.  I know these guys are doing something similar with their cmdlet to return a dispstatus - it would be nice to achieve the same result using PowerShell with standard executables that are included with an SAP kernel.


I have been applying modified versions of PowerShell scripts you've posted on SCN to ease administration and I have to say they are much less cumbersome to build/maintain than what I had previously drawn up via cmd.

Thanks,

Jeff

Answers (6)

Answers (6)

claudiageissler
Explorer
0 Kudos

Hello to all of you,

the batch file is working pretty good. But unfortunately only with those SAP systems with instance number 00.

The reason ist easy. In checkallrfcs.bat there is the line:FOR /F %%i in (SAPsystems.txt) do call CheckRFC %%i 00

So parameter 00 is later %2 in CheckRFC.bat file. But 00 is a constant. We also have systems with instance number 01 and so on. How could I handle this?

Any ideas?

best regards,

Claudia Geissler

Former Member
0 Kudos

ok so know i changed my script to just use the SAPIFNO in the cmd to check for my sap systems like below :

sapinfo ashost=server1  sysnr=00

sapinfo ashost=server2  sysnr=00

sapinfo ashost=server3  sysnr=00

it worked for all exeapt for the Entrpirse portal servers DEV and PRO and the BO (Business Object) server it gives me this error :

Group       Error group 102

Key         RFC_ERROR_COMMUNICATION

Message     SAP_CMINIT3 : rc=20 > Connect to SAP gateway failed

Connect_PM  GWHOST=10.2.4.80, GWSERV=sapgw00, SYSNR=00

LOCATION    CPIC (TCP/IP) on local host

ERROR       partner '10.2.4.80:3300' not reached

TIME        Mon Mar 17 12:25:28 2014

RELEASE     730

COMPONENT   NI (network interface)

VERSION     40

RC          -10

MODULE      nixxi.cpp

LINE        3286

DETAIL      NiPConnect2: 10.2.4.80:3300

SYSTEM CALL connect

ERRNO       10061

ERRNO TEXT  WSAECONNREFUSED: Connection refused

COUNTER     1

however the systems are up and running ,, i have tried this script with a down server it gave me same error as above

Former Member
0 Kudos

When i try to use normal sapinfo cmd : sapinfo ashost=MySERVER sysnr=00

i get this error :

Group       Error group 102

Key         RFC_ERROR_COMMUNICATION

Message     SAP_CMINIT3 : rc=20 > Connect to SAP gateway failed

Connect_PM  GWHOST=myserver, GWSERV=sapgw00, SYSNR=00

LOCATION    CPIC (TCP/IP) on local host

ERROR       partner '92.242.144.5:3300' not reached

TIME        Sun Mar 16 13:51:18 2014

RELEASE     730

COMPONENT   NI (network interface)

VERSION     40

RC          -10

MODULE      nixxi.cpp

LINE        3286

DETAIL      NiPConnect2: 92.242.144.5:3300

SYSTEM CALL connect

ERRNO       10060

ERRNO TEXT  WSAETIMEDOUT: Connection timed out

COUNTER     1

former_member182034
Active Contributor
0 Kudos

hi Dear,

sapinfo ashost=MySERVER sysnr=00

what is the name of you machine,

Please mention the machine name instead MyServer and try again.


Regards,



Former Member
0 Kudos

Dear,

Yes that what i did , i just changed it back to myserver here as an example

Former Member
0 Kudos

Can someone send me the SAPINFO.exe file cause i cant find it on the SAPGUI CD or in my machine or pc so please send it to me cause i am using one that i downloaded and i think it is the problem

Thank In advance

Regards,

Ahmed Salam

former_member182034
Active Contributor
0 Kudos

Dear Ahmed,

You can download from below link.

sapinfo

Regards,

Former Member
0 Kudos

this is where i have downloaded it

ok should ii place it in a specific dir. or what ?

Regards,

former_member182034
Active Contributor
0 Kudos

aoa ahmed,

You can put in any directory and execute it after browse the path of sapinfo.exe.

Regards,

Former Member
0 Kudos

Yes i put it in the same folder as the bat files and run the checkallrfc.bat i get this error now :

C:>FOR /F %i in (SAPsystems.txt)

do call checkrfc %i 00

C:>call checkrfc TestSolman 00

PingingTestSolman ...

System does not exist on the network!

Press any key to continue . . .

i fixed the invalid switch error but i get this one however i tryed to ping the server and it reply .

Former Member
0 Kudos

just to be honest:

you can run sapinfo.exe interactively and it is working as supposed?

If you do not install the executable with the appropriate tools, you may miss a necessary compontent (Microsoft Visual Studio runtime?)

former_member182034
Active Contributor
0 Kudos

hi Ahmed,

Please check the instruction which are in below link.

Tips and Tricks

Try to run batch file in window command prompt and share the result.

Regards,

Former Member
0 Kudos

Dear M.Abdul Jamil ,

Thanks for answering me But , This Link is the source of the above work i made i tryed batching the command files like he stated and i am stuck at the result i shared above.

Regards

Ahmed Salam.

former_member182034
Active Contributor
0 Kudos

Dear Ahmed,

now when i run checkallrfc.bat it opens a command windows and automaticlly close it in less than 2 sec

put the pause in the end of your batch file then open this batch file and share the result.


Regards,


Former Member
0 Kudos

Nothing changed please give me the pause sytex maybe i am doing it wrong .

Sriram2009
Active Contributor
0 Kudos

Hi Ahmed

Just a query  where you are define the SAPSYSTEMs.txt file in CheckRFC.bat?

BR

SS

former_member182034
Active Contributor
0 Kudos

just write the pause in the end of batch file and execute this batch file. Now batch file will not be closed before press any key.

Regards,

Former Member
0 Kudos

its in the checkallrfc.bat and that file called check rfc.bat

Former Member
0 Kudos

Dear Abdul Jamil,

I tried but its keep closing , ps i recently readied an article that says that the SAPINFO uses hard coded user and i should 1st grant this user access to the systems so i currently finding out more about that part

Former Member
0 Kudos

dear Abdul jamil,

I have tried the pause on the Checkallrfc.bat file and it worked and helped me to find that i was having a wrong syntax with the checkrfc.bat file thank you for that , however here is the result of the cmd prompt :

C:>FOR /F %i in (SAPsystems.txt)

do call checkrfc %i 00

C:>call checkrfc TESTSOLMAN 00

Pinging 1 ...

FIND: Invalid switch

System does not exist on the network!

Pinging 1 ...

FIND: Invalid switch

System does not exist on the network!

Press any key to continue . . .

former_member182034
Active Contributor
0 Kudos

hi Ahmed,

If your system exist on the Network which you can confirm with the help of PING command then check the Firewall setting which should be Ok.

Please also contact with Network Team about this issue because Script Is looking Ok now.

Regards,