Sqlplus - S stops ...sigh !

Discussion in 'Perl' started by Gianni, Jun 17, 2004.

  1. Gianni

    Gianni Guest

    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
     
    Gianni, Jun 17, 2004
    #1
    1. Advertising

  2. Gianni

    Jim Gibson Guest

    In article <>, Gianni
    <> 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.
     
    Jim Gibson, Jun 17, 2004
    #2
    1. Advertising

  3. Gianni

    Gianni Guest

    Jim Gibson <> wrote in message news:<170620041232264167%>...
    > In article <>, Gianni
    > <> 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
     
    Gianni, Jun 18, 2004
    #3
  4. Gianni

    Tim X Guest

    >>>>> "Gianni" == Gianni <> 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!
     
    Tim X, Jun 19, 2004
    #4
  5. Gianni

    Karel Kubat Guest

    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 <, >
    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.
     
    Karel Kubat, Jul 1, 2004
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gianni

    Sqlplus -S interrupt !!!!

    Gianni, Jun 17, 2004, in forum: Perl
    Replies:
    0
    Views:
    2,957
    Gianni
    Jun 17, 2004
  2. =?Utf-8?B?c2FtbXk=?=

    asp.net worker does not load up ...SIGH

    =?Utf-8?B?c2FtbXk=?=, Dec 30, 2004, in forum: ASP .Net
    Replies:
    7
    Views:
    2,128
    Steven Cheng[MSFT]
    Jan 17, 2005
  3. Replies:
    1
    Views:
    808
    Martin v. Löwis
    Jan 24, 2008
  4. Daniel Berger

    Driving Oracle sqlplus with open3

    Daniel Berger, Jul 26, 2006, in forum: Ruby
    Replies:
    11
    Views:
    291
    Pra Bhandar
    Mar 3, 2009
  5. The alMIGHTY N

    SQLPlus with Perl

    The alMIGHTY N, Nov 2, 2006, in forum: Perl Misc
    Replies:
    7
    Views:
    1,724
    Peter Scott
    Nov 3, 2006
Loading...

Share This Page