Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent!! Inserting UNIX enviroment variables in a Perl script

Status
Not open for further replies.

Dudek

Technical User
Jan 14, 2002
27
MY
Hi there...

I currently have a perl script. I was wondering whether it was possible for me to include into the script the environment variables in my unix .profile file into the Perl script. The reason for this is, i need the cron job to run the script automatically every day. But when the cron runs it, it will spill out error messages that are because of different path settings and environment settings. So what i need is a way such that when the cron runs the script, it will also run it using my logins .profile or environment settings.

Can anybody help me here? Quite urgent..

TIA

JD
 
Hi,
I'm not sure if this will work for UNIX but for DOS & windows envs perl creates a datahash called %ENV. So to use the localdrive set by the env just use

$localdrive = $ENV{LOCALDRIVE}

hope this helps,
JV
 
Three suggestions:
1) Manually source the profile from cron
Code:
0,30 * * * *  . /path/to/.profile; myscript
2) Will not work for csh .profile
Code:
require "dotsh.pl";
&dotsh( "/path/to/.profile" );
3) Supply defaults when %ENV not valid
Code:
$value = $ENV{'value'} || "xyz";
Cheers, Neil
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top