Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
Home -> Community -> Mailing Lists -> Oracle-L -> Re: Perl script to verify DB is up.
On Wed, 21 Jun 2000, Mabry, Jennifer wrote:
> Hello all,
>
> I and my group are pretty new DBA's and have a question for you all.
>
> Do any of you have a UNIX Perl script that monitors each of your instances
> to verify the DB is up? If not, pages you?
>
Here's a basic connect script.
The paging would be fairly easy to add by using a Perl Sendmail module.
Jared Still
Certified Oracle DBA and Part Time Perl Evangelist ;-)
Regence BlueCross BlueShield of Oregon
jkstill_at_bcbso.com - Work - preferred address
jkstill_at_teleport.com - private
#!/usr/bin/perl
use DBI;
use strict;
no strict 'vars';
use Getopt::Long;
my %optctl = ();
Getopt::Long::GetOptions(\%optctl, "database:s","username:s","password:s","z","h","help");
#setup environment - homegrown package
my($db, $username, $password);
if ( ! defined($optctl{database}) ) {
Usage(); die "database required\n";
if ( ! defined($optctl{username}) ) {
Usage(); die "username required\n";
if ( ! defined($optctl{password}) ) {
Usage(); die "password required\n";
#print "USERNAME: $username\n"; #print "DATABASE: $db\n"; #print "PASSWORD: $password\n"; #exit; # setup your Oracle environment before running this # or ( less optimal ) set it up here # $ENV{ORACLE_SID}='my_sid';
$dbh = DBI->connect('dbi:Oracle:' . $db, $username, $password, { RaiseError => 1, AutoCommit => 0 } );
die "Connect to $db failed \n" unless $dbh;
$MySql="select \* from dual";
$sth = $dbh->prepare($MySql);
my $rv = $sth->execute;
while( $ary = $sth->fetchrow_arrayref ) {
print "\t\t$${ary[0]}\n";
}
$sth->finish;
$dbh->disconnect;
sub Usage {
print "\n"; print "usage: connect.pl\n"; print " connect.pl -database dv07 -username scott -password tiger\n";Received on Wed Jun 21 2000 - 11:29:53 CDT