-- Script for Finding Invalid Directories.
-- Create a test file and check for the status
declare
f utl_file.file_type;
BEGIN
FOR X IN ( SELECT * FROM DBA_DIRECTORIES WHERE OWNER= 'SYS' ) LOOP
BEGIN
f := utl_file.fopen(x.directory_name,'madhu_test.txt','W');
IF utl_file.is_open(f) THEN
UTL_FILE.fclose(f);
UTL_FILE.fremove(x.directory_name,'madhu_test.txt');
end if;
EXCEPTION
WHEN OTHERS THEN dbms_output.put_line(x.directory_name || ' -- ' || x.directory_path || ' is invalid');
END;
END LOOP;
END;
/
Tuesday, June 30, 2009
Perl Script to shutdown/startup all dbs on a server. oratab_shutdown_startup.pl
#!/usr/bin/perl
#########################################################################
# Shutdown or Startup all the databases from oratab file with a Y flag.
# pass shutdown or startup parameter
#########################################################################
use strict;
my $ORATAB;
my @fields;
my $SPOOL_FILE;
my $cmd;
my $result;
# Validate Input Parameter. STARTUP or SHUTDOWN
if ( lc($ARGV[0]) eq "startup") { $cmd = "startup" ; }
elsif ( lc($ARGV[0]) eq "shutdown") { $cmd = "shutdown immediate" ; }
else { print "Invalid Argument. Pass either shutdown or startup" . "\n"; exit; }
print $cmd . "\n";
# Get ORATAB file
if (-e '/etc/oratab') { $ORATAB='/etc/oratab'; }
elsif (-e '/var/opt/oracle/oratab') { $ORATAB='/var/opt/oracle/oratab'; }
else { print "oratab not found, please check manually", "\n"; exit; }
# Loop thu each entry in the oratab
open FILE, $ORATAB || die("Could not ORATAB!");
while () {
chomp; # chops off what is in $/
next if /^#/; # discard comments
next if /^\s+$/; # discard blank lines
@fields=split(/:/,$_); # Split the oratab entry into 3 fields
next if (@fields[2] ne "Y"); # discard if the 3rd variable is not Y
print "Processing " . @fields[0] . " " . @fields[1] . "\n";
$ENV{'ORACLE_SID'} = @fields[0];
$ENV{'ORACLE_HOME'} = @fields[1];
$SPOOL_FILE=@fields[0] . "_list.out";
$result = `@fields[1]/bin/sqlplus "/as sysdba" < $cmd
exit
END
`;
print $result,"\n";
}
close FILE;
exit;
#########################################################################
# Shutdown or Startup all the databases from oratab file with a Y flag.
# pass shutdown or startup parameter
#########################################################################
use strict;
my $ORATAB;
my @fields;
my $SPOOL_FILE;
my $cmd;
my $result;
# Validate Input Parameter. STARTUP or SHUTDOWN
if ( lc($ARGV[0]) eq "startup") { $cmd = "startup" ; }
elsif ( lc($ARGV[0]) eq "shutdown") { $cmd = "shutdown immediate" ; }
else { print "Invalid Argument. Pass either shutdown or startup" . "\n"; exit; }
print $cmd . "\n";
# Get ORATAB file
if (-e '/etc/oratab') { $ORATAB='/etc/oratab'; }
elsif (-e '/var/opt/oracle/oratab') { $ORATAB='/var/opt/oracle/oratab'; }
else { print "oratab not found, please check manually", "\n"; exit; }
# Loop thu each entry in the oratab
open FILE, $ORATAB || die("Could not ORATAB!");
while (
chomp; # chops off what is in $/
next if /^#/; # discard comments
next if /^\s+$/; # discard blank lines
@fields=split(/:/,$_); # Split the oratab entry into 3 fields
next if (@fields[2] ne "Y"); # discard if the 3rd variable is not Y
print "Processing " . @fields[0] . " " . @fields[1] . "\n";
$ENV{'ORACLE_SID'} = @fields[0];
$ENV{'ORACLE_HOME'} = @fields[1];
$SPOOL_FILE=@fields[0] . "_list.out";
$result = `@fields[1]/bin/sqlplus "/as sysdba" <
exit
END
`;
print $result,"\n";
}
close FILE;
exit;
Subscribe to:
Posts (Atom)