-1
system("$sqlldr $oracleLogon control=$ctlFile log=$logFile data=$dateFile"); 

Above is the last line of my perl script. When I run script which containing this line manually (from cli) it works. But when I put it to crontab, getting fail.

Variable $sqlldr contains full path of Oracle's sqlldr script including its. Of course, all of variables containing full path including file names.

Also my script calls "system" many times and all of those are running fine expecting last this line. I'm using Ubuntu 10.04 server 64bit and I put my script into user oracle's crontab.
I really can't stand what goes on there. Can anyone help me please?

TLP
  • 66,756
  • 10
  • 92
  • 149
tsoomo
  • 95
  • 7
  • 4
    "Getting fail" is not a very good description of your error. Show the assignment of the variables and error messages. – TLP Dec 01 '11 at 11:49
  • -1 for not including the error message. – tadmc Dec 01 '11 at 15:00
  • 1
    when you run it from the CLI, are you running it as the oracle user? If not, then you most likely have a permission problem somewhere. – tadmc Dec 01 '11 at 15:02

2 Answers2

3

Check the difference between environments in case of CLI and cron - that will be the key to understanding the issue.

Just before your system(..) call in perl put:

system("env > ~/env_in_cron.txt");

and compare this with env called in CLI.

pmod
  • 10,450
  • 1
  • 37
  • 50
  • Thank you very much. I should set cron environment like user oracle. My mistake was "If I set crontab for specified user that means ENV set must be same according to /home/user/.profile" – tsoomo Dec 02 '11 at 03:15
2

When a script works on the command line but not with crontab, it is often because of environment differences.

In your case, you are trying to execute an Oracle tool. And all Oracle tools need the ORACLE_HOME environment variable. Those variables are set when using a terminal but not when using crontab.

In your script, try setting and exporting ORACLE_HOME to your Oracle client before launching SQL*Loader.

And please post your error message. If it fails silently, try redirecting STDOUT and STDERR to a file from your crontab call and post the result.

Stamm
  • 947
  • 5
  • 17