Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Sqlplus - S stops ...sigh !

Reply
Thread Tools

Sqlplus - S stops ...sigh !

 
 
Gianni
Guest
Posts: n/a
 
      06-17-2004
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
 
Reply With Quote
 
 
 
 
Jim Gibson
Guest
Posts: n/a
 
      06-17-2004
In article <(E-Mail Removed) >, Gianni
<(E-Mail Removed)> wrote:

> 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.
 
Reply With Quote
 
 
 
 
Gianni
Guest
Posts: n/a
 
      06-18-2004
Jim Gibson <(E-Mail Removed)> wrote in message news:<170620041232264167%(E-Mail Removed) >...
> In article <(E-Mail Removed) >, Gianni
> <(E-Mail Removed)> wrote:
>
> > 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.


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
 
Reply With Quote
 
Tim X
Guest
Posts: n/a
 
      06-19-2004
>>>>> "Gianni" == Gianni <(E-Mail Removed)> writes:

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



--
Tim Cross
The e-mail address on this message is FALSE (obviously!). My real e-mail is
to a company in Australia called rapttech and my login is tcross - if you
really need to send mail, you should be able to work it out!
 
Reply With Quote
 
Karel Kubat
Guest
Posts: n/a
 
      07-01-2004
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 <(E-Mail Removed), http://www.velocityreviews.com/forums/(E-Mail 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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Driving Oracle sqlplus with open3 Daniel Berger Ruby 11 03-03-2009 12:41 AM
os.system behavior when calling SQLPlus with spooling steve551979@hotmail.com Python 1 01-24-2008 05:17 AM
SQLPlus with Perl The alMIGHTY N Perl Misc 7 11-03-2006 01:57 PM
Wireless Stops Working Norbert Lieckfeldt Wireless Networking 1 09-05-2004 12:28 AM
Sqlplus -S interrupt !!!! Gianni Perl 0 06-17-2004 02:01 PM



Advertisments