-
September 2nd, 2011, 01:39 AM
#1
Batch script with condition?
Hi guys!
I would like to create batch script for doing bunch of databases TNSPING with certain condition.
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 executed 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!
-
September 2nd, 2011, 08:36 AM
#2
Re: Batch script with condition?
It's not really complicated if your tnsping tool returns a value to the OS that indicates whether any error has occurred. I don't know that particular program but many such tools do that. They return a value of 0 in case of success, anything else means some sort of error. You may find something about that in the tnsping documentation, but these return codes are often undocumented, so it's worth a try even if you don't find something about that.
Exploiting the return code, you can first redirect the tnsping output to a temporary log file and then append that temporary file to your actual log file only in case of an error. Somewhat like this:
Code:
tnsping >temp.log
if errorlevel 1 type temp.log >>tnsping.log
If tnsping doesn't indicate success/failure that way the whole thing becomes much more complicated...
I was thrown out of college for cheating on the metaphysics exam; I looked into the soul of the boy sitting next to me.
This is a snakeskin jacket! And for me it's a symbol of my individuality, and my belief... in personal freedom.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|