The following works:

use DBI;

my $database;
my $address = "[EMAIL PROTECTED]";
my %attr;
my $dbh;
my $sid;
open MAIL, "|mail $address";
open DBFILE, "</u01/app/oracle/check_list.txt";

while ($sid = <DBFILE>) {
chomp($sid);
$ENV{ORACLE_SID} = $sid;
print "$ENV{ORACLE_SID}\n";
$dbh = DBI->connect( "dbi:Oracle:$database", "", "", \%attr)
        or print MAIL "Could not connect to database: $ENV{ORACLE_SID}
$DBI::errstr\n";
}
close MAIL;


The == was wrong, I couldn't remember the rule, and = produced a result
of 1, ie. I realized now the chomp evaluated to true or 1.  I'm not
masquerading as multiple users, only 1 user externally identified.  This
simply means the user is authenticated by the OS, and not the database.
This also allows the script to be run by any externally identified user.
Once connected normal database security takes over.

The problem now is that the script won't connect to any remote
databases.  I assume this is probably because of the external
identification.  While the oracle user is externally identified on all
servers, I probably have to log in to each server before connecting.


-----Original Message-----
From: Jay [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, February 22, 2005 10:41 AM
To: Jason Wozniak
Cc: beginners@perl.org
Subject: Re: Environment variables

On Mon, 21 Feb 2005 16:14:43 -0500, Jason Wozniak <[EMAIL PROTECTED]>
wrote:
> That's what I thought, but it doesn't work, which is why I tried
system.
> 
> The below code:
> 
> use DBI;
> 
> my $database;
> #my $address = "[EMAIL PROTECTED]";
> my $address = "[EMAIL PROTECTED]";
> my %attr;
> my $dbh;
> open MAIL, "|mail $address";
> open DBFILE, "</u01/app/oracle/check_list.txt";
> 
> while (<DBFILE>) {
> $ENV{ORACLE_SID} == chomp($_);
> print "$ENV{ORACLE_SID}\n";
> $dbh = DBI->connect( "dbi:Oracle:$database", "", "", \%attr)
>         or print MAIL "Could not connect to database: $ENV{ORACLE_SID}
> $DBI::errstr\n";
> }
> close MAIL;
> 
> produces the following output:
> 
> P01
> P01
> P01
> P01
> P01
> 
> The file /u01/app/oracle/check_list.txt contains several different
sids,
> and if I print $_ it is reading them in.
> 

Jason,

I'm not sure about this, but it seems to me that ORACLE_SID is
probably set by some system process after you log into the database,
and can't be reset by the user.  Have you tried resetting from the
shell using export (or whatever command is appropriate for your
shell)?  Allowing what you're trying to do--a combination of
passwordless login and masquerading as multiple users--would be a very
insecure.  I certainly wouldn't want my data stored anywhere you could
get away with this.

That said, try actually assigning the variable in the loop.  "==" is a
test for numerical equality. "=" is for variable assignment.  Turn on
use strict and use warnings to help you clean up your code; you may
find there aren't as many problems as you think there are.  On the
other hand, the shell has read only variables; this may be one of
them.  Getting this to work may require writing the script to run as
root (or the oracle user) using Perl::IPC or similar to manipulate the
tty/pty info.  You'll probably have to feed it passwords at some
point, though.  A server that just takes your word for your user id is
a server you want to steer very clear of.

--jay



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to