In this case, it may not work. It all depends on who's crontab the script is executed from and what that user's home directory is. For instance, if it is in the Apache user's crontab and their home is /var/www, then that's where the script would be executed, and would not know how to find the 'lib' dir from there, as it would first have to locate 'cgi-bin'.

One can test where cron scripts are being run out of by using the following code snip:

#!/usr/bin/perl use warnings; use strict; use Cwd; print getcwd();

Then, set up a crontab to call the script and output the result to a file (this entry is for root):

$ sudo crontab -e * * * * * /home/steve/cron.pl > /home/steve/cron.out

That prints "/root" to the 'cron.out' file.

Set up a crontab for my personal user that does the same thing, and cron.out will contain '/home/steve'. If the OP puts something like this into the crontab of the user calling the real script, it'll identify the issue immediately.

There are always two common problems when trying to run a script from cron. The first is that cron does not have environment variables set (unless you do so explicitly in the crontab), so it has no knowledge of PATH. This means that you must specify a full path to the script cron is trying to call. The other common issue is what we're seeing in the OP's post (from what I can tell), where cron can execute the script, but the location it is being run out of is not what is expected.

Using full paths is the easiest way to get cron-run scripts to do the right thing. If one does need to use a relative path, it must be relative to the home directory of the user who's crontab is running the script.


In reply to Re^3: Perl module path not found by stevieb
in thread Perl module path not found by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.