Perl can't find module when run from cron.daily

前端 未结 2 1164
梦毁少年i
梦毁少年i 2021-01-05 12:49

I have perl programs that use Net::Finger and have run successfully from cron.daily in Fedora 11.
I just upgraded a server to Fedora 18 and the

2条回答
  •  死守一世寂寞
    2021-01-05 13:15

    See perlfaq8.

    Here are three ways to add arbitrary directories to Perl's module search path.

    1. Set the PERL5LIB environment variable

      15 15 * * 1-5 PERL5LIB=/root/perl5/lib/perl5 /usr/local/bin/perl my_script.pl
      
    2. Use the -I command line switch

      15 15 * * 1-5 /usr/local/bin/perl -I/root/perl5/lib/perl5 my_script.pl
      
    3. Use the lib pragma inside your perl script

      #! /usr/local/bin/perl
      # my_script.pl: the script that does my thing
      use lib '/root/perl5/lib/perl5';
      use Net::Finger;
      ...
      

    Also note that the environment of a cron job is much sparser than the environment of your command line, and in particular the cron environment's $PATH variable might not be what you expect. If you're not specifying the full path to the Perl executable, verify what $PATH the cron environment is using and make sure you are running the right version of perl.

提交回复
热议问题