Operating System - HP-UX
1832594 Members
2789 Online
110043 Solutions
New Discussion

Re: Another Perl Brainbuster

 
SOLVED
Go to solution
Scott_130
Occasional Advisor

Another Perl Brainbuster

I am running a script that conects to Oracle using DBI and DBD:ORACLE

it works fine from the command line but not from cron (since the env resets). The workaround is to run the cron as root and have a side-script that does and su - oracle and runs the script.
I have tried putting vars into the ENV hash in multiple ways and while it looks correct, the system is not reading them properly.

ex. ENV{ORACLE_HOME)=''
ENV{ORACLE_HOME)=""

Is there a way from within a perl script to leave the script and set the shell environment and re-enter the script or set the env from within the script?

Any help would be generously appreciated.

Thanks

Scott
4 REPLIES 4
Chris Wilshaw
Honored Contributor
Solution

Re: Another Perl Brainbuster

Normally, you source in the environment within the cron job, prior to running the job itself

eg

0 1 * * * . env_file;script >/dev/null 2>&1

You just need to make sure that the env file has all the variables (PATH etc) set that you require.
H.Merijn Brand (procura
Honored Contributor

Re: Another Perl Brainbuster

Hmmm, does nout sound as it should. Maybe a BEGIN block would help

BEGIN {
$ENV{ORACLE_HOME} = "/path/to/your/oracle/home";
}

It could be that the connect call is done /before/ the environments are set, which busts the procedure
Enjoy, Have FUN! H.Merijn
A. Clay Stephenson
Acclaimed Contributor

Re: Another Perl Brainbuster

Try this:

$ENV{"ORACLE_HOME"}="xxx/yyy";
$ENV{ORACLE_SID}="demo";

Now make your system call and all will be well.

Plan B:

Don't use that su - oracle stuff but rather use su oracle.

Both Oracle's .profile and your wrapper shell script should source a file (e.g. /usr/local/bin/oraenv.sh) that sets and exports any needed env vars but does not contain an exit or return. .profiles often contain commands which expect an interactive environment. This causes problem when jobs are croned.

e.g.
#!/usr/bin/sh

PATH=${PATH}:/usr/local/bin
export PATH
. /usr/local/bin/oraenv.sh
/usr/bin/perl myorascript.pl
STAT=${?}
exit ${STAT}

If it ain't broke, I can fix that.
Scott_130
Occasional Advisor

Re: Another Perl Brainbuster

Wow thanks. I created a little env file and set the environment like you said in the cron script:

. /
and it worked like a charm. Thanks a lot.

FYI: I meant to say $ENV previously and i said ENV.
Sorry A. Clay