LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   Trouble with perl script in Cron job (https://www.linuxquestions.org/questions/linux-general-1/trouble-with-perl-script-in-cron-job-194599/)

thack111 06-17-2004 10:30 AM

Trouble with perl script in Cron job
 
Sorry if this has been covered, I have never used cron before and am having trouble. I have a perl script that runs fine from my user, but errors when cron runs it. Here is the error in my email:

Message 1:
From th3491@blackboxL.mo.sbc.com Thu Jun 17 10:20:00 2004
Date: Thu, 17 Jun 2004 10:20:00 -0500
From: root@blackboxL.mo.sbc.com (Cron Daemon)
To: th3491@blackboxL.mo.sbc.com
Subject: Cron <th3491@blackboxL> /home/common/xscript/oracleFinal/importCurrentWork.pl
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/home/th3491>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=th3491>

ORACLE_HOME environment variable not set!
DBI connect('TSH1','th3491',...) failed: (UNKNOWN OCI STATUS 1804) OCIInitialize. Check ORACLE_HOME and NLS settings etc. at /home/common/xscript/oracleFinal/importCurrentWork.pl line 17


This looks to me like it is not setting all my environment variables like it does when I log in. my .bash_profile takes care of it when I log in. I added

system '/home/th3491/.bash_profile';
to the perl code, but it says I don't have permission. This is new to me and I have read everything I can find, I have even found in forums where people say you need to set your environment variables, but I don't know how.

here is my crontab entry if it helps:

# Job to import CurrentWork MOKA NTX STX
5,20,35,50 7-18 * * * /home/common/xscript/oracleFinal/importCurrentWork.pl


Thanks in advance for any help.
Todd

nukkel 06-17-2004 10:37 AM

I think you could write a "wrapper" script in shellscript -- that way the shell will set the env. vars. Kinda like this
Code:

#!/bin/sh
source /home/th3491/.bash_profile
/home/common/xscript/oracleFinal/importCurrentWork.pl

then run that script from the crontab.

Cheers
nukkel

thack111 06-17-2004 12:00 PM

That seems to have fixed my problem, Thank you very much for the help.

nukkel 06-17-2004 12:28 PM

No problem! Happy unixing :)

andresurzagasti 11-24-2004 02:02 PM

Similar problem
 
Hi!
I have a similar problem with a some configuration.

Im scheduled in crontab a pppd connection (dialup), with the set of scripts

/usr/sbin/ppp-on
/etc/ppp/ppp-on-dialer
/usr/sbin/ppp-off

I can connect OK if I run directly from shell the script /usr/sbin/ppp-on,
but If the connection is scheduled by crontab, pppd returns the message "Connect script failed"

I have read and test with a wrapper script, but this does not resolve my problem.

Any ideas?
Regards
Andres
Argentina

nukkel 11-24-2004 03:40 PM

Hi,

Do you use /etc/crontab, or per-user crontabs in /var/spool/cron/tabs?
Because maybe your script needs to be run as root (?), but when you use the per-user crontab then it will not be run as root. In that case it's best to put the line in question in /etc/crontab, and put "root" between the first 5 fields and the command.

Other than that I don't see if there could be another reason the script failed... :scratch:

Or maybe you could edit the script so it gives a little more output? That could help to track down where exactly it is failing...

nukkel

andresurzagasti 11-24-2004 05:20 PM

Solution OK
 
Hi nukkel!

Thanks, The script have been runing from per-user crontab.
I have just modified and replace the script with the options in /etc/crontab and works OK

regards

Andres

nukkel 11-25-2004 02:44 AM

Good to hear it worked!

Cheers
nukkel


All times are GMT -5. The time now is 07:25 PM.