By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,848 Members | 1,290 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,848 IT Pros & Developers. It's quick & easy.

Cron does not find method in required library

P: 2
Hi, long time listener, first time caller so to speak. Thanks to everyone who has answered other questions that I've found and used.

I'm self-taught in Perl and have been hacking at it for more than five years now, so your patience with me is appreciated.

Here's my issue. I have a Perl script (say, myscript.cgi) that is set to run on a cron job. It has a require line to another function library. (This is a procedural program, not OO):

require "";

The library is in the same directory as the script. When i call the script using a browser, it renders fine in the browser. i.e.,

When I set the same myscript.cgi to run as a cron job, I get an error that one of the functions in can't be found:
Undefined subroutine &main::my_subroutine called at /home/my_username/public_html/mysite/cgi-bin/myscript.cgi line 77, <FHANDLE> line 6.

Here's the rub: there are several calls in myscript to functions located in mylib. It is only functions that are added to the library recently that cause this failure. In other words, if the code hasn't changed in a while, it runs fine, regardless of where the procedure is located. But if I create a new procedure in, the cron version won't run it.

I am no expert on perl compilation, but if I am guessing that the problem is the cron job sees some cached version of my script somewhere and runs that one, failing to recompile and see my new function.

Does anyone know if my hunch is right? If so, how do I force it to recompile? Or am I totally off track?

Thanks in advance, it is very much appreciated.
Mar 6 '08 #1
Share this Question
Share on Google+
3 Replies

Expert 100+
P: 971
I would try adding the absolute path to the file and add the die function.

Expand|Select|Wrap|Line Numbers
  1. require '/path/to/' || die "Can't open /path/to/ $!\n"; 
Mar 6 '08 #2

Expert 2.5K+
P: 4,059
You wouldn'ty be the first person that thought they were editing and saving a file in the correct directory but come to find they weren't. So make sure the file is the correct one that your main perl script is using.
Mar 6 '08 #3

P: 2
Thank you both for your replies, and I apologize for the delay in getting back to you.

I inserted a hard path to the Perl library, and verified using a hard "print" that it's the right one. The program ran under the cron and did not fail on the die clause.

However, I found an old portion of the code that included a relative path. Once corrected, the code now runs fine.

Thank for the advice that pointed me in the right direction. It's appreciated.
Mar 7 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.