1751907 Members
5323 Online
108783 Solutions
New Discussion юеВ

DBI-Oracle

 
SOLVED
Go to solution
rgoud
Occasional Advisor

DBI-Oracle

Hi list,
I am getting errors when I execute this code, if I replace $Logevent with a text it
works fine but I am not sure why it is giving errors. This is a simple code which will
test the database is up or down, if it is down I want to create a event in the event
log on NT. Here is the script ...
$ cat dbamon.pl
#!C:\perl\ActivePerl\Perl\bin\perl -w

use strict;
use DBI;

my $dbh = DBI->connect( 'dbi:Oracle:db1',
'test',
'test',
{
RaiseError => 1,
AutoCommit => 0
}
) || die "Database connection not made: $DBI::er
rstr";

my $sql = qq( SELECT status from test );
my $sth = $dbh->prepare( $sql );
$sth->execute();

my( $status);
$sth->bind_columns(undef, \$status);

$Logevent=`C:/perlwork/logevent -s E -r "Backup Event" -e 42 "Producti
on Database is down"`

while( $sth->fetch() ) {
if($status eq "Success")
{print "$status:Good\n"};
else
{print "$Logevent"};
}

$sth->finish();
$dbh->disconnect();


$ ./dbamon.pl
Global symbol "$Logevent" requires explicit package name at C:\perlwor
k\dbamon.pl line 22.
syntax error at C:\perlwork\dbamon.pl line 24, near ") {"
Execution of C:\perlwork\dbamon.pl aborted due to compilation errors.

Thanks in advance
5 REPLIES 5
Ross Zubritski
Trusted Contributor

Re: DBI-Oracle

$Logevent=`C:/perlwork/logevent -s E -r "Backup Event" -e 42 "Producti
on Database is down"`

Aren't those supposed to be "\", not "/"?

Regards.

RZ
rgoud
Occasional Advisor

Re: DBI-Oracle

That's my mistake but even if I run with logevent in the current path I am getting same error.
$Logevent=`logevent -s E -r "Backup Event" -e 42 "Producti
on Database is down"`
H.Merijn Brand (procura
Honored Contributor

Re: DBI-Oracle

Have you tried with

$dbh->trace (9);

?

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
H.Merijn Brand (procura
Honored Contributor
Solution

Re: DBI-Oracle

Have you tried with

$dbh->trace (9);

?

Ah, and the warning is because you didn't declare $Logevent as lexical:

my $Logevent=`C:/perlwork/logevent -s E -r "Backup Event" -e 42 "Producti
on Database is down"`

BTW

my $status;

does not need parentheses

Enjoy, have FUN! H.Merijn
Enjoy, Have FUN! H.Merijn
rgoud
Occasional Advisor

Re: DBI-Oracle

t