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

Forgive me,

I have the following script owned by root (/jobs/scripts/runscript):
perl /jobs/scripts/script.pl perl /jobs/scripts/script.pl 3
Executing as root does what I'd expect.

I set a cron.d job with the following:
0 7 * * * root /jobs/scripts/runscript
Problem:
Cron fails: Can't locate Time/HiRes.pm in @INC (@INC ... (blah, bla +h).
I assumed that since crond is running this as root, there would be no problem..

How can I resolve this?

Your wisdom is most kindly appreciated (in advance)

Thank you.

Bill

Janitored by holli - fixed formatting

Replies are listed 'Best First'.
Re: crond INC problem
by gsiems (Deacon) on May 26, 2005 at 18:19 UTC
    This (/jobs/scripts/runscript) is a shell script, no? Try setting your path environment variable prior to calling the perl scripts. i.e.:
    export PATH=/bin:/usr/bin:/usr/local/bin:/foo:/bar:/baz perl /jobs/scripts/script.pl perl /jobs/scripts/script.pl 3

      You might also consider sourcing your login environment rc file (presuming of course you use a shell that supports separate "environment rc" and "interactive rc" file). For example I use zsh and pure environment settings are in ~/.zshenv while interactive aliases and prompts and what not are in ~/.zshrc. If I need a cron job to have the same environment I'm used to at a prompt I just source ~/.zshenv. Even if your shell doesn't explicitly support this it might be worth breaking environment setup out into another file you can source from stuff run from cron.

      --
      We're looking for people in ATL

Re: crond INC problem
by Tanktalus (Canon) on May 26, 2005 at 18:00 UTC

    Cron may not be using your environment. So it may be running the wrong perl if you have more than one installed. Try specifying the full path to perl in your crontab entry.

      Perfect. Done. Thank you for your sanity and wisdom. I forgot that I had a separate installation, but I also thought crond (running as root) would implement root's environment.
Re: crond INC problem
by brian_d_foy (Abbot) on May 26, 2005 at 19:14 UTC

    It looks like perl can't find it's libraries.

    As others have already said, cron runs with a limited environment, including a limited PATH. Some things to consider:

    • Are you running the perl binary you think you are? Since the PATH is different, it might be finding another perl (and another Config.pm which lists a different @INC).
    • Does your shell environment have a PERL5LIB? You'll need that in the crontab too, or you can use lib qw() inside the script.

    If neither of thosee fix it we'll have to get more creative.

    Good luck! :)

    --
    brian d foy <brian@stonehenge.com>