Help please with sourcing an environment variable 
Author Message
 Help please with sourcing an environment variable

Hi, I hope someone can help me

I need to read the value of an environment variable from a shell script in a
perl cgi. The reason being that it uses a DBI call to Oracle and we need to
make the Oracle password non static, the actual password is held centrally
in the shell script that gets run by normal binaries.

I am aware of the issues around trying to do this kind of thing, using
system etc won't work. I have searched the newsgroups and found a couple of
suggestions and also asked at the office, but I have been unable to get any
of them working.

I'll say now, I am not experienced with perl, but I have programming
experience and basic unix knowledge and some html

The perl script gets called from a java applet, puts up a search screen,
accepts the input and generates another page with the results.

First thing I tried was a shell wrapper eg.

#!/bin/sh
.  /export/home/...........

However when the script does the post the mime type seems to get changed and
the browser prompts me to save a file (which is the html page that should
get displayed)

Next one was an untested suggestion, eg

in the script use something like

$ENV{DB_USER} = `. <path to shell script>; echo $DB_USER`;
$ENV{DB_PASSWD} = `. <path to shell script>; echo $DB_PASSWD`;

however this just returns what looks like a newline character, no strings.

Final thing I tried is a bit of a hack, which apparently is part shell, part
perl

at the top of the perl script


I get an error in the apache log complaining about a bad exec format.

Apart from loading the shell script and parsing the values is there any
other way of achieving what I am trying to do?

Many thanks

Simon Barnard
Technical Support Services
Solect, A Division of Amdocs



Mon, 10 Nov 2003 17:06:39 GMT  
 Help please with sourcing an environment variable

MCMXCIII in <URL::">
&&  
&&  $ENV{DB_USER} = `. <path to shell script>; echo $DB_USER`;
&&  $ENV{DB_PASSWD} = `. <path to shell script>; echo $DB_PASSWD`;

$DB_USER and $DB_PASSWD are interpolated by Perl before the line is passed
to the shell. You would need to escape the $ signs with a backslash.

Abigail
--
perl5.004 -wMMath::BigInt -e'$^V=Math::BigInt->new(qq]$^F$^W783$[$%9889$^F47]
.qq]$|88768$^W596577669$%$^W5$^F3364$[$^W$^F$|838747$[8889739$%$|$^F673$%$^W]
^V
%$^U;$^V/=$^U}while$^V!=$^W'



Mon, 10 Nov 2003 19:43:53 GMT  
 Help please with sourcing an environment variable

Quote:


> &&
> &&  $ENV{DB_USER} = `. <path to shell script>; echo $DB_USER`;
> &&  $ENV{DB_PASSWD} = `. <path to shell script>; echo $DB_PASSWD`;

> $DB_USER and $DB_PASSWD are interpolated by Perl before the line is
> passed to the shell. You would need to escape the $ signs with a
> backslash.

Or else use qx and '

chomp $ENV{DB_USER}   = qx'. <path to shell script>; echo $DB_USER  ';
chomp $ENV{DB_PASSWD} = qx'. <path to shell script>; echo $DB_PASSWD';

Of course, it would be better to do both assignments at once:

        . <path to shell script>
        echo $DB_USER
        echo $DB_PASSWD';

You also need chomp on the `` version, unless DBI ignores a trailing
newline on the userid and password.

--
The longer a man is wrong, the surer he is that he's right.



Tue, 02 Dec 2003 13:23:52 GMT  
 Help please with sourcing an environment variable

Quote:



> > &&
> > &&  $ENV{DB_USER} = `. <path to shell script>; echo $DB_USER`;
> > &&  $ENV{DB_PASSWD} = `. <path to shell script>; echo $DB_PASSWD`;

> > $DB_USER and $DB_PASSWD are interpolated by Perl before the line is
> > passed to the shell. You would need to escape the $ signs with a
> > backslash.

> Or else use qx and '

And use chomp correctly.

Quote:
> chomp $ENV{DB_USER}   = qx'. <path to shell script>; echo $DB_USER  ';
> chomp $ENV{DB_PASSWD} = qx'. <path to shell script>; echo $DB_PASSWD';

chomp( $ENV{DB_USER}   = qx'. <path to shell script>; echo $DB_USER  '
);
chomp( $ENV{DB_PASSWD} = qx'. <path to shell script>; echo $DB_PASSWD'
);

Quote:
> Of course, it would be better to do both assignments at once:

>         . <path to shell script>
>         echo $DB_USER
>         echo $DB_PASSWD';


        . <path to shell script>;
        echo $DB_USER;
        echo $DB_PASSWD' );

Quote:
> You also need chomp on the `` version, unless DBI ignores a trailing
> newline on the userid and password.

John
--
use Perl;
program
fulfillment


Tue, 02 Dec 2003 17:26:58 GMT  
 Help please with sourcing an environment variable

Quote:




> > > &&
> > > &&  $ENV{DB_USER} = `. <path to shell script>; echo $DB_USER`;
> > > &&  $ENV{DB_PASSWD} = `. <path to shell script>; echo $DB_PASSWD`;

> > > $DB_USER and $DB_PASSWD are interpolated by Perl before the line is
> > > passed to the shell. You would need to escape the $ signs with a
> > > backslash.

> > Or else use qx and '

> And use chomp correctly.

> > chomp $ENV{DB_USER}   = qx'. <path to shell script>; echo $DB_USER  ';
> > chomp $ENV{DB_PASSWD} = qx'. <path to shell script>; echo $DB_PASSWD';

> chomp( $ENV{DB_USER}   = qx'. <path to shell script>; echo $DB_USER  ' );
> chomp( $ENV{DB_PASSWD} = qx'. <path to shell script>; echo $DB_PASSWD' );

> > Of course, it would be better to do both assignments at once:

> >         . <path to shell script>
> >         echo $DB_USER
> >         echo $DB_PASSWD';


>         . <path to shell script>;
>         echo $DB_USER;
>         echo $DB_PASSWD' );

This seems to be an instance of perl's binding being un-DWIMish.  Why
doesn't the assignment have a higher precedence than the chomp?

--
The longer a man is wrong, the surer he is that he's right.



Wed, 03 Dec 2003 13:42:25 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Sourcing Unix environment file?

2. setting env variables, sourcing, etc.

3. Help setting Environment variables

4. Newbie needs help: Environment variables

5. HELP : Setting an Environment Variable/ERRORLEVEL in PERL for NT

6. Help with environment variables

7. HELP! environment variables and rexec

8. newbie help need on environment variables

9. exporting perl variable into and environment variable

10. Variable Name - HELP PLEASE!!!!!

11. Please help me how is easiest way to extract text between some variable text

12. s///g interpolation and tied or overloaded variables (was: newbies question about backreference, please help)

 

 
Powered by phpBB® Forum Software