Quantcast
Channel: Doyensys Allappsdba Blog..
Viewing all articles
Browse latest Browse all 1640

TNS_NAME_PERL

$
0
0
#! /usr/local/bin/perl

# ----------------------------------------------------------------------------
#  Read an Oracle TNSNAMES.ORA file and load the definitions into a list
#  of Oracle Name Servers. This is similar to executing the LOAD_TNSNAMES
#  command, available from Oracle8i, on all Name Servers.
#
#  Usage: ./namesload.pl | namesctl


$TNSNAMES = "./tnsnames.ora";
@NAMESERVERS = (oranamesrvr0,oranamesrvr1,oranamesrvr2);

foreach $NS (@NAMESERVERS) {
        print "\nset server " . $NS . "\n\n";
        &register_name_servers;
        &load_tnsnames;
}
print "\n\nexit\n";
exit;

#--------------------------------------------------------------------------
sub register_name_servers {
   #
   # Register all NameServers. The defualt port is 1575.
   #
   print "register oranamesrvr0.world -t ORACLE_NAMESERVER -d " .
        "(ADDRESS=(PROTOCOL=TCP)(HOST=oranamesrvr0)(PORT=1575))\n\n";
   print "register oranamesrvr1.world -t ORACLE_NAMESERVER -d " .
        "(ADDRESS=(PROTOCOL=TCP)(HOST=oranamesrvr1)(PORT=1575))\n\n";
   print "register oranamesrvr2.world -t ORACLE_NAMESERVER -d " .
                "(ADDRESS=(PROTOCOL=TCP)(HOST=oranamesrvr2)(PORT=1575))\n";
}

#--------------------------------------------------------------------------
sub load_tnsnames {
   #
   # Read the TNSNAMES.ORA file and generate NAMESCTL register commands
   #
   $service = "";
   open(FIL, $TNSNAMES);
   while (<FIL>) {
        if ( substr($_, 0, 1) eq '#' ) {
                # Ignore comments...
        } elsif ( substr($_, 0, 1) eq '' || substr($_, 1, 1) eq '\t' ) {
                s/ //g; s/\n//g;
                $body = $body . $_;
        } else {
           if ( $service ne "" ) {
              print "\n\nREGISTER ".$service." -t ORACLE_DATABASE -d ".$body;
           }
           $service = substr($_, 0, index($_, ''));
           $body    = '';
        }
   }
   print "\n\nREGISTER ".$service." -t ORACLE_DATABASE -d ".$body;
   close(FIL);
}

#EOF

Viewing all articles
Browse latest Browse all 1640

Trending Articles