cancel
Showing results for 
Search instead for 
Did you mean: 

Perl Problem in Cron

Allan_40
Occasional Visitor

Perl Problem in Cron

Hi Everybody,

I've been solving this problem for days now and still i can't make it work. I have perl script that load data in our database. In the command line, i can successfully run my perl script via shell script. But, when i try to do it via cron then problem begins....

This is what i'm getting:

Can't exec "sqlldr": No such file or directory

I read this is caused by not properly setting the ENV.

How can i set my ENV right?
Do i need to add additional lines in my script? in shell? in perl? or in cron?

Pls. i need your help.

If my problem is already been discussed i would gladly apprciate if you post the thread link..

Thanks...
7 REPLIES
Patrick Wallek
Honored Contributor

Re: Perl Problem in Cron

You MUST explicitly set your path within your script. Either fully qualify the path to the sqlldr command or export your PATH within the script.

Allan_40
Occasional Visitor

Re: Perl Problem in Cron

Hi Patrick,

Thanks for your quick reply.

Yes i read a lot of thread saying that i should include the PATH or ENV...but, how can i do it? should i do it i my perl script? or shell?

Thanks.
Bill Hassell
Honored Contributor

Re: Perl Problem in Cron

All scripts, whether shell or Perl, etc must have *all* the variables set as required by your script. If you login and type this command:

export PATH=

Now you'll find that all Unix commands and programs cannot be found. When put commands like cut and awk and grep in a script, they can't be found unless the PATH crutch is available. So many sysadmins have forgotten about PATH that they don't really know where the command is located. Now change PATH to:

export PATH=/usr/bin

and now vi and grep and awk can be found. PATH is one of dozens of environment variables in your 'normal' login. cron does not login so it does not inherit any of these values. So restore your basic PATH value by typing:

export PATH=$(cat /etc/PATH)

Now to see your login environment, type the commands: set and env. The set command shows everything, env shows just the exported values. You can capture the env output and add it to your script. But the better way is to examine your script to see what it (and commands that you use in the script) needs. Then code those into your script.


Bill Hassell, sysadmin
Petr Simik_1
Valued Contributor

Re: Perl Problem in Cron

you can simpy copy PATH from your .profile to shell script which is in crontab.
copy PATH from env

In crontab you have to allways setup path for everything. You you have output/input log config files they all have to be defined.
like this in example.

/u01/app/oracle/product/8.0.6/bin/sqlldr user/pass control=/dir/foo logfile=/dir/log
Fred Ruffet
Honored Contributor

Re: Perl Problem in Cron

an example :
I do not have . in my PATH.

$ ln -s /bin/ls ls_in_home_dir
$ perl
system("ls_in_home_dir");

Nothing happens (system call doesn't work cause not finding the program). Now I put . in PATH using ENV:

$ perl
$ENV{'PATH'}.=":.";
system("ls_in_home_dir");
bin
docs
log
ls_in_home_dir
scripts

That's all :)

Regards,

Fred
--

"Reality is just a point of view." (P. K. D.)
Allan_40
Occasional Visitor

Re: Perl Problem in Cron

Hi to everybody...

I'd like to thank you all for your quick reply...

I already fixed the problem...finally!!

I just added these lines in my perl script

$ENV{ORACLE_BASE}='/oracle';
$ENV{ORACLE_SID}='cdsdbdev';
$ENV{ORACLE_HOME}='/oracle/app/product/10.1.0.2/db';

Thank you all!!!!
R. Allan Hicks
Trusted Contributor

Re: Perl Problem in Cron

Just a style point that you may want to consider......

I have a script called ora_defaults that sets up the oracle environment. I source it at the beginning of all my scripts so that I know the environment is set up correctly.

example:

#!/usr/bin/ksh
. /home/oracle/ora_defaults

This saves you should your oracle home, oracle_sid, etc. should change.

BTW - Good name Allan
-Good Luck
Allan Hicks
"Only he who attempts the absurd is capable of achieving the impossible