LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 06-17-2004, 11:30 AM   #1
thack111
LQ Newbie
 
Registered: Sep 2003
Posts: 18

Rep: Reputation: 0
Question 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
 
Old 06-17-2004, 11:37 AM   #2
nukkel
Member
 
Registered: Mar 2003
Location: Belgium
Distribution: Hardened gentoo
Posts: 323

Rep: Reputation: 30
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
 
Old 06-17-2004, 01:00 PM   #3
thack111
LQ Newbie
 
Registered: Sep 2003
Posts: 18

Original Poster
Rep: Reputation: 0
That seems to have fixed my problem, Thank you very much for the help.
 
Old 06-17-2004, 01:28 PM   #4
nukkel
Member
 
Registered: Mar 2003
Location: Belgium
Distribution: Hardened gentoo
Posts: 323

Rep: Reputation: 30
No problem! Happy unixing
 
Old 11-24-2004, 03:02 PM   #5
andresurzagasti
Member
 
Registered: Sep 2002
Location: Reconquista
Distribution: RedHat, Fedora
Posts: 38

Rep: Reputation: 15
Question 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

Last edited by andresurzagasti; 11-24-2004 at 03:56 PM.
 
Old 11-24-2004, 04:40 PM   #6
nukkel
Member
 
Registered: Mar 2003
Location: Belgium
Distribution: Hardened gentoo
Posts: 323

Rep: Reputation: 30
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...

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
 
Old 11-24-2004, 06:20 PM   #7
andresurzagasti
Member
 
Registered: Sep 2002
Location: Reconquista
Distribution: RedHat, Fedora
Posts: 38

Rep: Reputation: 15
Smile 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
 
Old 11-25-2004, 03:44 AM   #8
nukkel
Member
 
Registered: Mar 2003
Location: Belgium
Distribution: Hardened gentoo
Posts: 323

Rep: Reputation: 30
Good to hear it worked!

Cheers
nukkel
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cron Job with a Script bravored Linux - General 4 08-05-2005 11:27 AM
cron job for expect script ruchitadesai Programming 9 05-27-2005 05:34 AM
Cron Job not running ssh script karim0028 Linux - General 3 02-07-2005 01:08 PM
script not running as a cron job sanjith11 Programming 5 11-23-2004 09:42 AM
shell script fo run auto job in cron JolynnMarie LinuxQuestions.org Member Intro 0 04-28-2004 12:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:30 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration