Friends...
(Question from newbie, sorry if this is too much in detailed but trying to provide all details to avoid any confusion) I'm working on a script which search for all SID entries from Oracle tnsentry file and use distinct SID list to connect and query database for the result.
Oracle tnsentry file has got many duplicates with (SID = DB), so trying to use only distinct SID entry.
I can easily connect to single database by providing db name but we have 10 database so it gets bit tricky to
read tnsentry file (tnsfile.txt)
Search for db alias (SID = db1 , SID = db2 etc)
Store each db alias temporary into array
Use each alias for db connection in $dbConnect function
Mycode try:
#!/usr/bin/perl
use strict;
my $uNamePass = "user/password";
my @dbName;
#Uses username password and dbName to connect databsae
# e.g. user/password@db1
foreach my $item(@dbName) {
$dbConnect = &connect($uNamePass."@".$dbName);
&getRows;
}
exit($exitStatus);
#------------
sub readFile {
my $fName = "c:\tnsentry.txt";
my $dbName;
# open file
if ( ! open (DAT, $fName) ) {
¨
}
# read file by each line
while(<DAT>) {
chomp;
# if line begins with # sign, proceed to next
next if /^\#/;
# Next not able to figure out how to read each line and store distin
+ct
# DB name in an array to use for login in $dbConnect
# I think I need to sepearte SID with /SID/ and search for string ti
+ll it reaches ')'
}
Sample: tnsentry.txt
DB1=
(
(ADDRESS = (PROTOCOL = TCP))
...
...
(CONNECT_DATA = (SID = db1))
)
DB2=
(
(ADDRESS = (PROTOCOL = TCP))
...
...
(CONNECT_DATA = (SID = db2))
)
DB3=
(
(ADDRESS = (PROTOCOL = TCP))
...
...
(CONNECT_DATA = (SID = db3))
)
DB_ONE=
(
(ADDRESS = (PROTOCOL = TCP))
...
...
(CONNECT_DATA = (SID = db1))
)
DB_TWO=
(
(ADDRESS = (PROTOCOL = TCP))
...
...
(CONNECT_DATA = (SID = db2 ))
)
"SID = db1" or "SID = dbn" can appear multiple times in the file so don't want to connect same database multiple times and run query
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.