neversaint has asked for the wisdom of the Perl Monks concerning the following question:

Dear Masters,
I would like to run my Perl script every 15 minutes. And my crontab looks like this:
MAILTO=neversaint@somehost.com */15 * * * * /usr/bin/perl /home/neversaint/MyPerl/Somedir/myscript.pl
Furthermore in myscript.pl also uses a module (List::Compare). However the script above doesn't seem to get executed. And it fails to recognize the location of the module, by emailing me this message:
Can't locate List/Compare.pm in @INC (@INC contains: ..etc
Is there something wrong with my Crontab setting?

Update: The script works in the normal situation under my linux shell, but not in this cron (thanks to sgifford's clarification).

---
neversaint and everlastingly indebted.......

Replies are listed 'Best First'.
Re: Chronicling Perl script and recognition of modules location with Crontab
by sgifford (Prior) on Sep 22, 2006 at 05:13 UTC
    Assuming that the script works from your shell command-line, the problem is likely to be the different environment the cron job runs in. For example, maybe you have PERL5LIB in your environment, and cron probably won't.

    The easiest way to troubleshoot this specific problem would be to see where List/Compare.pm is located, then make sure that directory is at the top of your script with a use lib statement.

    Another idea is to run a shell with no environment, with something like env - bash. Getting your script to work in that environment should ensure it works with cron as well.

Re: Chronicling Perl script and recognition of modules location with Crontab
by ysth (Canon) on Sep 22, 2006 at 05:13 UTC
    If it's emailing you, it's because it ran the script and got the Can't locate... on stderr. Is List/Compare.pm in one of the directories listed? If not, fix it or adjust @INC with PERL5LIB= or perl -I ... or use lib, etc.
Re: Chronicling Perl script and recognition of modules location with Crontab
by cephas (Pilgrim) on Sep 22, 2006 at 11:35 UTC
    As someone pointed out, there is likey an environment difference. To elaborate on that, cron clears out the entire environment, with the exception of: HOME, LOGNAME, TZ, PATH, SHELL. It should be executing the bourne shell (not bash), not matter what your login normally uses.