Operating System - HP-UX
1833875 Members
2915 Online
110063 Solutions
New Discussion

Re: syntax to source env. variables in perl

 
SOLVED
Go to solution
Ratzie
Super Advisor

syntax to source env. variables in perl

I hava script that runs with out a hitch from command line but as soon as a cron it, it hangs.

In the script it source environment files, but I am tending to lean towards it may not.
...
# Set up environment for the bins/sqlplus
system('. /etc/access/db/oraenv');
system('. /home/admin/.db_env');
...

Now in the same crontab the only way it will work is by adding the env in the cron. Is there a better way?

00 05 * * 2-6 (. /etc/accesss/db/oraenv;. /home/admin/.db_env; /home/admin/scripts/sysadmin/acxld/acxld.pl -C) > /dev/null 2>&1



4 REPLIES 4
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: syntax to source env. variables in perl

$ENV{MYVAR1}="xxx";
$ENV{MYVAR2}="yyy";
system("env"};

Note that the "env" command now displays the 2 new env. vars for you. ENV is a hash in Perl.


If it ain't broke, I can fix that.
Fred Ruffet
Honored Contributor

Re: syntax to source env. variables in perl

from "perldoc -f keys" :

Here is yet another way to print your environment:

@keys = keys %ENV;
@values = values %ENV;
while (@keys) {
print pop(@keys), '=', pop(@values), "\n";
}

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Hein van den Heuvel
Honored Contributor

Re: syntax to source env. variables in perl

and:

perl -e 'foreach $k(sort keys %ENV) { print "$k=$ENV{$k}\n" }'

Hein.
Ratzie
Super Advisor

Re: syntax to source env. variables in perl

Thanks