Cron does not find method in required library

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Zudnic
    New Member
    • Mar 2008
    • 2

    Cron does not find method in required library

    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 "mylib.pl";

    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.,
    http://myserver.com/cgi-bin/myscript.cgi

    When I set the same myscript.cgi to run as a cron job, I get an error that one of the functions in mylib.pl can't be found:
    Undefined subroutine &main::my_s ubroutine called at /home/my_username/public_html/mysite/cgi-bin/myscript.cgi line 77, <FHANDLE& gt; 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 mylib.pl, 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.
  • eWish
    Recognized Expert Contributor
    • Jul 2007
    • 973

    #2
    I would try adding the absolute path to the file and add the die function.

    [CODE=perl]
    require '/path/to/file.pl' || die "Can't open /path/to/file.pl: $!\n"; [/CODE]
    --Kevin

    Comment

    • KevinADC
      Recognized Expert Specialist
      • Jan 2007
      • 4092

      #3
      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.

      Comment

      • Zudnic
        New Member
        • Mar 2008
        • 2

        #4
        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.

        Comment

        Working...