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

Windows perl script for Oracle Home

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



use Win32::Registry;

usage() if $#ARGV == -1;

my $Reg = "SOFTWARE\\Oracle\\ALL_HOMES";
my ($hakey, @key_list, $key);

$HKEY_LOCAL_MACHINE->Open($Reg,$hakey)|| die $!;
$hakey ->GetKeys(\@key_list);
$hakey->Close();
foreach $key (@key_list)
{
        #print "$key\n";
        &getpath("$Reg\\$key");
        setpath() if $found eq "TRUE";
}
notfound() if $found eq "FALSE";

sub notfound
{
 print "Sorry Oracle Home not found\n";
}

sub setpath
{
  $_ = $ENV{'PATH'};
  $newpath = $orapath."\\bin;";
  my @items = split /;/;
  $foundinpath = "FALSE";
  for ($i = 0; $i <= $#items; $i++)
  {
          if (uc($items[$i]) ne uc($orapath."\\bin"))
          {
           if ($i < $#items)
           {$newpath = $newpath.$items[$i].";";};
          }
          if (uc($items[$i]) eq uc($orapath."\\bin"))
          {
            $foundinpath = "TRUE";
          }
  }
if ($foundinpath eq "TRUE") {$newpath=$newpath.$items[$#items];};
#$ENV{'Path'} = $newpath;
print "set PATH=$newpath\n";
print "set ORACLE_HOME=$orapath";
exit ( 0 );
}

sub getpath
{
use Win32::Registry;
my %RegType = (
            0 => 'REG_0',
            1 => 'REG_SZ',
            2 => 'REG_EXPAND_SZ',
            3 => 'REG_BINARY',
            4 => 'REG_DWORD',
            5 => 'REG_DWORD_BIG_ENDIAN',
            6 => 'REG_LINK',
            7 => 'REG_MULTI_SZ',
            8 => 'REG_RESOURCE_LIST',
            9 => 'REG_FULL_RESOURCE_DESCRIPTION',
            10 => 'REG_RESSOURCE_REQUIREMENT_MAP');

my $Register = $_[0];
my $RegType, $RegValue, $RegKey, $value;
my %values;

$HKEY_LOCAL_MACHINE->Open($Register,$hkey)|| die $!;

$hkey->GetValues(\%values);
$found = "FALSE";

foreach $value (keys(%values))
    {
    $RegType     = $values{$value}->[1];
    $RegValue     = $values{$value}->[2];
    $RegKey     = $values{$value}->[0];
    next if ($RegType eq '');  #do not print default value if not assigned
    $RegKey     = 'Default' if ($RegKey eq '');    #name the default key
        if (uc($RegKey) eq uc("NAME"))
        {
        if (uc($RegValue) eq uc($ARGV[0])) {$found = "TRUE";};
        }
        if ($RegKey eq "PATH" and $found eq "TRUE")
        {
        $orapath = $RegValue;
        #print uc("$RegValue\n");
        };
    }
$hkey->Close();
}

sub usage {
  print STDERR <<EOM;
Usage: orasel.pl oracle_home
Example `orasel.pl ora920'
EOM
  exit( 0 );
}

Viewing all articles
Browse latest Browse all 1640

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>