Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: Perl script to verify DB is up.

Re: Perl script to verify DB is up.

From: Jared Still <jkstill_at_bcbso.com>
Date: Wed, 21 Jun 2000 09:29:53 -0700 (PDT)
Message-Id: <10535.110019@fatcity.com>


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";

}
$db=$optctl{database};

if ( ! defined($optctl{username}) ) {

	Usage();
	die "username required\n";

}
$username=$optctl{username};

if ( ! defined($optctl{password}) ) {

	Usage();
	die "password required\n";

}
$password=$optctl{password};
#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';

# $ENV{ORACLE_HOME}='/obase/product/8.1.5'; # $ENV{TNS_ADMIN}='/obase/product/8.1.5/network/admin/';

$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

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US