RE: Environment variable problem?

2007-12-19 Thread John Scoles

Just a repost so other can learn from it
 
Cheers


Date: Wed, 19 Dec 2007 10:05:58 -0500From: [EMAIL PROTECTED]: [EMAIL 
PROTECTED]: Re: Environment variable problem?It wasn't permissions, I fixed it 
by adding my PATH to the crontab and now it works. Thanks for the help and 
enjoy the Holiday season.Sam
On 12/18/07, John Scoles [EMAIL PROTECTED] wrote: 

Looks like a simple permissions error. 1) check to ensure you have 
libclntsh.so.10.1 on you computer (This is an oracle client) if not then you 
will most likely have to recomple your DBD::Oracle against whatever Oracle 
client you wnat to use. See the readme for this  2) is you have 
libclntsh.so.10.1 make sure it is in the path and you have execute permissions 
hope this helps cheersJohn Scoles Date: Tue, 18 Dec 2007 10:59:44 -0500 From: 
[EMAIL PROTECTED] To: dbi-users@perl.org Subject: Environment variable 
problem? 
  I'm running Red Hat AS 4 on a Sunfire X4200 with 4 GB RAM,  
  2.6.9-67.ELsmp #1 SMP Wed Nov 7 13:58:04 EST 2007 i686 athlon i386 
  GNU/Linux Perl 5.8.5 installed with DBI 1.601 and DBD::Oracle 1.19, and 
  the Oracle 10.2.0.1 client at /usr/lib/oracle/10.2.0.1/client 
  ORACLE_HOME=/usr/lib/oracle/10.2.0.1/client 
  LD_LIBRARY_PATH=/usr/lib/oracle/10.2.0.1/client/lib  I have a lot of Perl 
  scripts that connect to an Oracle DB that work fine  from the command line 
  when run as root, and fail from crontab or with sudo when not run as root 
  directly.  I've tried including the ORACLE_HOME and LD_LIBRARY_PATH 
  environment variables in my crontab file, but they still fail. This fixed 
  a problem that  I had seen previously with Java, that was fixed when I 
  included JAVA_HOME in my crontab, so I was surprised when it failed with 
  Oracle DBD.  The error message that I get is  install_driver(Oracle) 
  failed: Can't load  
  '/usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi/auto/DBD/Oracle/Oracle.so'
   for module DBD::Oracle: libclntsh.so.10.1: cannot open shared object 
  file: No such file or directory at  
  /usr/lib/perl5/5.8.5/i386-linux-thread-multi/DynaLoader.pm line 230. at 
  (eval 3) line 3 Compilation failed in require at (eval 3) line 3. Perhaps 
  a required shared library or dll isn't installed where expected at  
  /usr/local/include/BbStatistics.pm line 73  This is false, the shared 
  library does exist at the specified location, with proper permissions. 
  -r-xr-xr-x 1 root root 183768 May 21 2007  
  /usr/lib/perl5/vendor_perl/5.8.5/i386-linux-thread-multi/auto/DBD/Oracle/Oracle.so
All of my scripts worked in previous environment, Red Hat AS 3 on a 
  Sunfire X4200 with 8 GB of RAM,  2.6.9-55.ELsmp #1 SMP Fri Apr 20 
  17:03:35 EDT 2007 i686 athlon i386 GNU/Linux perl 5.8.5, with DBD::Oracle 
  1.19 and DBI 1.601 and Oracle 8.1.7 
  LD_LIBRARY_PATH=/usr/oracle/product/8.1.7/lib  
  ORACLE_HOME=/usr/oracle/product/8.1.7  I had to load the following RPMs 
  with --nodeps option to get DBD::Oracle installed on my new machines, but 
  presumed that all was well when scripts worked from command line. Perhaps 
  this is part of the problem?  libsqlora8-2.3.3-2.el4.i386.rpm 
  php-squale-0.1.9-1.el4.i386.rpm libsqlora8-debuginfo-2.3.3-2.el4.i386.rpm 
  php-squale-debuginfo-0.1.9-1.el4.i386.rpm  
  libsqlora8-devel-2.3.3-2.el4.i386.rpm 
  python-squale-0.1.10-0.2.el4.i386.rpm perl-DBD-Oracle-1.19-1.el4.i386.rpm 
  squale-0.1.10-0.2.el4.i386.rpm 
  perl-DBD-Oracle-debuginfo-1.19-1.el4.i386.rpm  
  squale-debuginfo-0.1.10-0.2.el4.i386.rpm 
  php-modules-debuginfo-4.3.9-3.el4.i386.rpm 
  squale-devel-0.1.10-0.2.el4.i386.rpm php-oci8-4.3.9-3.el4.i386.rpm  I'm 
  in a time crunch to get these new servers online before Christmas, so  all 
  help is GREATLY appreciated. :) --  Sam Hoover CSO, CCIT Clemson 
  University, Clemson, SC [EMAIL PROTECTED] Cell: 864.633.7499 Office: 
  864.656.3567

Your chance to win great prizes with Telus and Windows Live Messenger for 
Mobile. Click here for more information!-- Sam HooverCSO, CCITClemson 
University, Clemson, [EMAIL PROTECTED]: 864.633.7499Office: 864.656.3567 
_
Read what Santa`s been up to! For all the latest, visit 
asksantaclaus.spaces.live.com!
http://asksantaclaus.spaces.live.com/

Re: environment variable

2007-01-22 Thread Peter J. Holzer
On 2007-01-19 12:01:29 -0800, Jonathan Leffler wrote:
 system(VAR=val /path/to/your/shell/script);
 
 Well, that worked nicely for me with Korn Shell (and would work with Bourne
 Shell), but won't work with C shell (again).

On Unix-like systems the system() function always invokes /bin/sh, not
the user's login shell, so you don't have to worry about that.

hp

-- 
   _  | Peter J. Holzer| If I wanted to be academically correct,
|_|_) | Sysadmin WSR   | I'd be programming in Java.
| |   | [EMAIL PROTECTED]  | I don't, and I'm not.
__/   | http://www.hjp.at/ |   -- Jesse Erlbaum on dbi-users


pgpEbXPU2MIDN.pgp
Description: PGP signature


RE: environment variable

2007-01-19 Thread Reidy, Ron
Oscar,

Short answer - you cannot (sort of).  This is because your shell script
will execute in a sub shell of your perl program.

However, you can do something like this:

# untested
system(export VAR=val; /path/to/your/shell/script.sh);

I think that might work for you.

--
Ron Reidy
Lead DBA
Array BioPharma, Inc.

-Original Message-
From: Oscar Gomez [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, January 17, 2007 8:59 AM
To: dbi-users@perl.org
Subject: environment variable

how can i export a variable from program perl to shell script through
environment 
variable.

Thank you

--
Open WebMail Project (http://openwebmail.org)


This electronic message transmission is a PRIVATE communication which contains
information which may be confidential or privileged. The information is 
intended 
to be for the use of the individual or entity named above. If you are not the 
intended recipient, please be aware that any disclosure, copying, distribution 
or use of the contents of this information is prohibited. Please notify the
sender  of the delivery error by replying to this message, or notify us by
telephone (877-633-2436, ext. 0), and then delete it from your system.



Re: environment variable

2007-01-19 Thread Scott Smith

Reidy, Ron wrote:

Oscar,

Short answer - you cannot (sort of).  This is because your shell script
will execute in a sub shell of your perl program.

However, you can do something like this:

# untested
system(export VAR=val; /path/to/your/shell/script.sh);


The shell also takes a series of zero or more key-value pairs at the start of 
any command:

system(VAR=val VAR2=anotherval /path/to/any/program);

This has the same effect as exporting when you're doing it with Perl's system call, but it's good to 
keep in mind when you don't want to keep the variable setting or override in your general shell 
session. i.e.


LD_PRELOAD=/usr/lib/special_old_library.so /usr/bin/oldprogram

Scott Smith
Genome Sequencing Center




Re: environment variable

2007-01-19 Thread Jonathan Leffler

The solution I proposed works - and I tested it.

#!/bin/perl -w
$ENV{MY_ENVIRONMENT_VARIABLE} = Quixotic Response;
system(env);

However, this is Perl - TMTOWTDI!

If you want to undo the setting after running the shell, either localize
%ENV or delete the new variable.

{
local(%ENV) = %ENV;
$ENV{MY_ENVIRONMENT_VARIABLE} = Quixotic Response;
system(env);
}

or

#!/bin/perl -w
$ENV{MY_ENVIRONMENT_VARIABLE} = Quixotic Response;
system(env);
delete $ENV{MY_ENVIRONMENT_VARIABLE};

Ron's solution won't work unless you are running a sane shell (C shell
doesn't like export, a true Bourne shell doesn't like export with the
assignment!).
And, if you're using a sane shell, you don't need the export, you can simply
write:

system(VAR=val /path/to/your/shell/script);

Well, that worked nicely for me with Korn Shell (and would work with Bourne
Shell), but won't work with C shell (again).  You can have multiple
environment variables set if you need to:

system(VAR1=val1 VAR2=val2 /usr/bin/env);

And Scott's response arrived before I sent this but after I'd typed it.

Find Csh Programming Considered Harmful via Google if you don't understand
why C shell is not a good idea.

On 1/19/07, Reidy, Ron [EMAIL PROTECTED] wrote:


Short answer - you cannot (sort of).  This is because your shell script
will execute in a sub shell of your perl program.

However, you can do something like this:

# untested
system(export VAR=val; /path/to/your/shell/script.sh);

I think that might work for you.

--
Ron Reidy
Lead DBA
Array BioPharma, Inc.

-Original Message-
From: Oscar Gomez [mailto:[EMAIL PROTECTED]
Sent: Wednesday, January 17, 2007 8:59 AM
To: dbi-users@perl.org
Subject: environment variable

how can i export a variable from program perl to shell script through
environment
variable.

Thank you

--
Open WebMail Project (http://openwebmail.org)


This electronic message transmission is a PRIVATE communication which
contains
information which may be confidential or privileged. The information is
intended
to be for the use of the individual or entity named above. If you are not
the
intended recipient, please be aware that any disclosure, copying,
distribution
or use of the contents of this information is prohibited. Please notify
the
sender  of the delivery error by replying to this message, or notify us by
telephone (877-633-2436, ext. 0), and then delete it from your system.





--
Jonathan Leffler [EMAIL PROTECTED]  #include disclaimer.h
Guardian of DBD::Informix - v2005.02 - http://dbi.perl.org
I don't suffer from insanity - I enjoy every minute of it.


RE: environment variable

2007-01-19 Thread Rutherdale, Will
The standard Unix semantics is this:  a child process inherits the
environment from its parent.  Therefore if you (export and) set an
environment variable in a process and then run a script, it will see
that environment variable.

Furthermore, _Programming Perl, 3rd ed_ by Wall et all says this about
%ENV on p. 661:
Setting a value in %ENV changes the environment for both your process
and child processes launched after the assignment.

I tried this test program and it worked:

$ENV{MCGILLICUDY} = 'corncob pipe';
system( qq{echo \$MCGILLICUDY} );

-Will


 -Original Message-
 From: Scott Smith [mailto:[EMAIL PROTECTED]
 Sent: Friday 19 January 2007 14:53
 To: Reidy, Ron
 Cc: Oscar Gomez; dbi-users@perl.org
 Subject: Re: environment variable


 Reidy, Ron wrote:
  Oscar,
 
  Short answer - you cannot (sort of).  This is because your
 shell script
  will execute in a sub shell of your perl program.
 
  However, you can do something like this:
 
  # untested
  system(export VAR=val; /path/to/your/shell/script.sh);

 The shell also takes a series of zero or more key-value pairs
 at the start of any command:

 system(VAR=val VAR2=anotherval /path/to/any/program);

 This has the same effect as exporting when you're doing it
 with Perl's system call, but it's good to
 keep in mind when you don't want to keep the variable setting
 or override in your general shell
 session. i.e.

 LD_PRELOAD=/usr/lib/special_old_library.so /usr/bin/oldprogram

 Scott Smith
 Genome Sequencing Center




 - - - - - Appended by Scientific Atlanta, a Cisco company - - - - - 
This e-mail and any attachments may contain information which is confidential,
proprietary, privileged or otherwise protected by law. The information is solely
intended for the named addressee (or a person responsible for delivering it to
the addressee). If you are not the intended recipient of this message, you are
not authorized to read, print, retain, copy or disseminate this message or any
part of it. If you have received this e-mail in error, please notify the sender
immediately by return e-mail and delete it from your computer.



Re: environment variable

2007-01-19 Thread Alexander Foken

Once more, there is more than one way to do it ...

Modifying %ENV, perhaps with local, seems to be the cleanest and fastest 
way. do { local $ENV{'FOO'}='bar'; local $ENV{'GOD'}='Larry'; 
system('/usr/local/bin/shellscript.sh','--do-something'); };


Fiddling with the shell in system() looks AT LEAST dangerous to me 
(assuming some of the environment values may come from the network). 
system FOO=$bar /usr/local/bin/shellscript.sh --do-something may look 
harmless, but what happens if $bar is x rm -rf $HOME; ?


On most Unix-like systems, there is /usr/bin/env, which does not only 
dump the environment, but may also modify or reset it before passing 
control to another program. Type man env to learn what env can to for 
you. Something like 
system('/usr/bin/env','-','FOO=bar','GOD=Larry','/usr/local/bin/shellscript.sh','--do-something') 
should work.


On Windows, think about porting the shell script to Perl.


Oh, by the way: What is the relation of this question to Perl's Database 
Interface?


Alexander

Oscar Gomez wrote:
how can i export a variable from program perl to shell script through environment 
variable.


Thank you

--
Open WebMail Project (http://openwebmail.org)
  


--
Alexander Foken
mailto:[EMAIL PROTECTED]  http://www.foken.de/alexander/



Re: environment variable - Mea Culpa

2007-01-19 Thread Jonathan Leffler

On 1/19/07, Jonathan Leffler [EMAIL PROTECTED] wrote:


The solution I proposed works [...]



I sent it on the 17th.  Unfortunately, I only sent it to Oscar, not to
dbi-users as well.

Sorry - my mistake - both then and earlier today.

This subject should now be closed.

--
Jonathan Leffler [EMAIL PROTECTED]  #include disclaimer.h
Guardian of DBD::Informix - v2005.02 - http://dbi.perl.org
I don't suffer from insanity - I enjoy every minute of it.