Page 1 of 1

Batch script with condition?

Posted: 01 Sep 2011 04:29
by prepek2000
Hi guys!
I would like to create batch script for doing bunch of databases TNSPING.
I have created one batch file aca.bat and put in there this:

tnsping test1.bb.com
tnsping test2.bb.com
tnsping test1.bb.com
.
.
.
then i have execute it from cmd prompt like this aca.bat >>tnsping.log

and in tnsping.log file i have different output reply for each of above databases


D:\DATA\sta8983\Desktop>tnsping test1.bb.com

TNS Ping Utility for 32-bit Windows: Version 10.1.0.2.0 - Production on 01-SEP-2011 11:20:39

Copyright (c) 1997, 2003, Oracle. All rights reserved.

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=test.bb.com)(Port=1639))(CONNECT_DATA=(SERVICE_NAME=test1.bb.com)))
OK (300 msec)

D:\DATA\sta8983\Desktop>tnsping test2.bb.com

TNS Ping Utility for 32-bit Windows: Version 10.1.0.2.0 - Production on 01-SEP-2011 11:20:39

Copyright (c) 1997, 2003, Oracle. All rights reserved.

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=server.bb.com)(Port=1837))(CONNECT_DATA=(SERVICE_NAME=test2.bb.com)))
TNS-12541: TNS:no listener

D:\DATA\sta8983\Desktop>tnsping test3.bb.com

TNS Ping Utility for 32-bit Windows: Version 10.1.0.2.0 - Production on 01-SEP-2011 11:20:39

Copyright (c) 1997, 2003, Oracle. All rights reserved.

Used parameter files:


Used TNSNAMES adapter to resolve the alias
Attempting to contact (DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(Host=manage.bb.com)(Port=1740))(CONNECT_DATA=(SID=test3.bb.com)))
TNS-12545: Connect failed because target host or object does not exist


So my question is it possible to create batch job which would going to put in log every dataabse which tnsping didnt finished with message OK at the end? I need to create that kind of list.

Thank you!

Re: Batch script with condition?

Posted: 01 Sep 2011 11:40
by aGerman
Does TNSPING return different %errorlevel% values depending on whether it succeeded or failed?

Regards
aGerman

Re: Batch script with condition?

Posted: 02 Sep 2011 00:23
by prepek2000
Yes it does. I can expect that there is 4-5 diff values output of each pinged database. So therefore i would like to have log only from those which are not with OK output.

Re: Batch script with condition?

Posted: 02 Sep 2011 10:28
by aGerman
Maybe it makes sense to write each single output into a temporary log file, then check the errorlevel and append the temporary file to your list only if errorlevel is greater than 0.

Code: Select all

>"tmp.log" tnsping test1.bb.com
if errorlevel 1 >>"tnsping.log" type "tmp.log"

>"tmp.log" tnsping test2.bb.com
if errorlevel 1 >>"tnsping.log" type "tmp.log"

>"tmp.log" tnsping test1.bb.com
if errorlevel 1 >>"tnsping.log" type "tmp.log"

del "tmp.log"

Regards
aGerman