tnsnames.ora parser

  • From: Jared Still <jkstill@xxxxxxxxx>
  • To: Oracle-L Freelists <oracle-l@xxxxxxxxxxxxx>
  • Date: Fri, 30 Apr 2010 11:28:59 -0700

Something I've wanted for some time now is a tnsname.ora parser.

I've searched quite a bit, and not found anything quite adequate.

The closest to hitting the mark was tnsparse.c, apparently by Stephane
Faroult.

It didn't return everything I wanted, and besides, I wanted it in Perl.  :)

The proper way to do this would be to build a grammar and use something
like bison, yacc or Parse::Yapp in Perl.

The problem with that is I have never learned to use yapp, and didn't want
to start today.  :)

Attached is a brute force type of parser for tnsnames.ora files.

Feel free to try it out if you are interested, and let me know if it breaks
or not.

So far it has successfully parsed quite a large and varied tnsnames.ora file
I have on hand.

It will not return everything from the tnsname.ora file.  What is does
return are the
values from the CONNECT_DATA and ADDRESSES.

It should probably check for SDU and some other things, but for the moment
it
works well enough.

Usage is simple.  Copy the attached files to a directory, and feed the
driver script
a tnsnames.ora file:

   perl tns_parser_driver.pl $ORACLE_HOME/network/admin/tnsnames.ora

You should see output like this:

============================================================
==== sample1
   ===== connect info
   key: service_name  value: sales.us.acme.com
   ===== address 0
   key: protocol  value: tcp
   key: port  value: 1630
   key: host  value: host1
   ===== address 1
   key: protocol  value: tcp
   key: port  value: 1630
   key: host  value: host2a
   ===== address 2
   key: protocol  value: tcp
   key: port  value: 1630
   key: host  value: host2b
   ===== address 3
   key: protocol  value: tcp
   key: port  value: 1521
   key: host  value: host3


Jared Still
Certifiable Oracle DBA and Part Time Perl Evangelist
Oracle Blog: http://jkstill.blogspot.com
Home Page: http://jaredstill.com

Other related posts: