Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

cronjob choking on require

Status
Not open for further replies.

nerri

Programmer
Sep 1, 2006
21
US
I have written a script that works from the command line. However, when I run it through cron, it crashes on one of the requires. There are three requires, all written in the same format, but one doesn't work. All three have the same execute permissions and are in the same directory. What can be causing this?
 
The problem is almost certainly in your @INC.

Try running the script from a subdirectory, and see if it still works. Ie, mirroring the way that the cron job would be calling it. If this fails, then you need to implicitly include the directory of the script within include

Code:
use lib 'your_scripts_directory';

There are many ways to dynamically set this, but let's confirm that is truly your problem first.
 
show us your require statements, remember that the cron user isn't necessarily the same user as your console user. So as well as permissions, you'll need to check the ownership.

As well as what MillerH said.;-)

HTH

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
I can't run it in a subdirectory of the directory where it sits as there are none. However, I ran it from a different directory where it runs as it should. In the cronjob I use the full path name. I have written the requires using the following syntax:
Code:
require('/export/home/me/code/program.pl');
Again the other two are exactly the same. I own all three files.
 
I believe you misunderstood what I proposed as a possible solution and test for your error.

Say your script's location is as you said above: /export/home/me/code/program.pl

Normally you would use the following commands to run your program:
Code:
$ cd /export/home/me/code/
$ ./program.pl

I suggested that you test to see if your program still works when run from an alternate directory, such as a sub or parent directory. ie

Code:
$ cd ..
$ code/program.pl

If the above does not execute correctly, then you need to fix your @INC like I specified in my earlier post. Otherwise, I'll let PaulTEG follow up with his advice and debugging attempt.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top