Sqlplus - S stops ...sigh !

G

Gianni

Im trying to access a database using sqlplus in this way:

$command = "sqlplus -S " . $usr . "/" . $pwrd . " \@miooop060.sql";
print "$command";
$status = system ($command);
print "status" . $status;

if I give the above line the correct user and password there is not
problem.
The problem is when I test the error and give that line the wrong user
and password.

The program writes to the console this error
ORA-01017: invalid username/password; logon denied
and stops. What I would like to do is to the write the error in some
logfile and go on with the program .
Any ideas ?
Thanks
Gianni
 
J

Jim Gibson

Gianni said:
Im trying to access a database using sqlplus in this way:

$command = "sqlplus -S " . $usr . "/" . $pwrd . " \@miooop060.sql";
print "$command";
$status = system ($command);
print "status" . $status;

if I give the above line the correct user and password there is not
problem.
The problem is when I test the error and give that line the wrong user
and password.

The program writes to the console this error
ORA-01017: invalid username/password; logon denied
and stops. What I would like to do is to the write the error in some
logfile and go on with the program .
Any ideas ?

Try "perldoc -q capture" for ways to capture output from external
commands.

FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.
 
G

Gianni

Jim Gibson said:
Try "perldoc -q capture" for ways to capture output from external
commands.

FYI: this newsgroup is defunct. Try comp.lang.perl.misc in the future.

Thanks for your solution ... but the big problem is the other one ...
when I give the wrong password the program stops !!!! how can I solve
this ?
Thanks
 
T

Tim X

Gianni> Im trying to access a database using sqlplus in this way:
Gianni> $command = "sqlplus -S " . $usr . "/" . $pwrd . "
Gianni> \@miooop060.sql"; print "$command"; $status = system
Gianni> ($command); print "status" . $status;

Gianni> if I give the above line the correct user and password there
Gianni> is not problem. The problem is when I test the error and
Gianni> give that line the wrong user and password.

Gianni> The program writes to the console this error ORA-01017:
Gianni> invalid username/password; logon denied and stops. What I
Gianni> would like to do is to the write the error in some logfile
Gianni> and go on with the program . Any ideas ? Thanks Gianni

I would try using a pipe instead of a system call to communicate with
sqlplus directly. This will (should) make it easier to capture the
output and it will mean your username and password are not visible on
the command line (which someone could capture and use).

Is been a while since I did any Oracle, but I suspect the reason your
program hangs when you give it the wrong username/password is because
sqlplus has prompted for you to enter another username/password and is
waiting for input.

Another solution which might work is to use the expect module - using
this module, you can programatically interact with sqlplus - if the
worng username or password is entered, you can take appropriate
action, such as killing the process etc.

Tim
 
K

Karel Kubat

Gianni:
Im trying to access a database using sqlplus in this way:

$command = "sqlplus -S " . $usr . "/" . $pwrd . " \@miooop060.sql";
print "$command";
$status = system ($command);
print "status" . $status;

if I give the above line the correct user and password there is not
problem.
The problem is when I test the error and give that line the wrong user
and password.
The program writes to the console this error
ORA-01017: invalid username/password; logon denied
and stops. What I would like to do is to the write the error in some
logfile and go on with the program .
Any ideas ?

Take a look at DBI and DBD::Oracle. What you can do, is this:

use strict;
use DBI;
use DBD::Oracle;

# Db connection handle:
my $dbh;
$dbh = DBI->connect ("dbi:Oracle:", "user/password\@dbname")
or die ("cannot connect: ", $dbh->errstr(), "\n");

# Statement handle:
my $sth = $dbh->prepare ("select a, b, c from mytable where d = 'xyzzy'")
or die ("cannot prepare: ", $dbh->errstr(), "\n");
$sth->execute()
or die ("cannot execute: ", $dbh->errstr(), "\n");
while (my ($a, $b, $c) = $sth->fetchrow_array()) {
print ("$a $b $c\n");
}

# All done:
$dbh->disconnect();

This all isn't an answer to your actual problem, which is capturing command
output. But it's neater as Oracle is concerned. To follow up your path, you
would need something like:

# Command to run. Make sure that stderr gets captured too.
my $cmd = "sqlplus whatever 2>&1";

open (IF, "$cmd |")
or die ("cannot start $cmd: $!\n");
while (<IF>) {
# Check for errors
print ("Oops... logon failed\n")
if (/nvalid username/password; logon denied/);
}
close (IF);

Hope this all helps..
Karel
--
Karel Kubat <[email protected], (e-mail address removed)>
Phone: mobile (+31) 6 2956 4861, office (+31) (0)38 46 06 125
PGP fingerprint: D76E 86EC B457 627A 0A87 0B8D DB71 6BCD 1CF2 6CD5

From the Science Exam Papers:
The cuckoo bird does not lay his own eggs.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,754
Messages
2,569,521
Members
44,995
Latest member
PinupduzSap

Latest Threads

Top