Perl从cron.daily运行时找不到模块 [英] Perl can't find module when run from cron.daily

查看:191
本文介绍了Perl从cron.daily运行时找不到模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有perl程序使用Net :: Finger,并从Fedora 11中的cron.daily成功运行。

我刚刚将服务器升级到Fedora 18,这些相同的perl程序不再从cron运行但以root身份登录时从命令行运行良好。

错误是:

无法在@INC中找到Net / Finger.pm(@INC包含:/ usr / )

(/ lib / perl5 / usr / local / share / perl5 / usr / lib64 / perl5 / vendor_perl / usr / share / perl5 / vendor_perl / usr / lib64 / perl5 / usr /模块的路径是/root/perl5/lib/perl5/Net/Finger.pm,但我不知道如何添加路径而不会导致更多的错误。
提前感谢。

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 these same perl programs no longer run from cron but run fine from command line when logged in as root.
The error is:
Can't locate Net/Finger.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .)
The path to the module is /root/perl5/lib/perl5/Net/Finger.pm but I can't figure out how to add the path without causing more errors. Thanks in advance.

推荐答案

请参阅 perlfaq8


  1. 设置 PERL5LIB 环境变量

15 15 * * 1-5 PERL5LIB=/root/perl5/lib/perl5 /usr/local/bin/perl my_script.pl


  • 使用 -I 命令行开关

  • Use the -I command line switch

    15 15 * * 1-5 /usr/local/bin/perl -I/root/perl5/lib/perl5 my_script.pl
    


  • 使用 lib pragma in your perl script

  • 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;
    ...
    







  • 还要注意,cron作业的环境比命令行的环境更加稀疏,特别是cron环境的 $ PATH 变量可能不是你期望的。如果您没有指定Perl可执行文件的完整路径,请验证cron环境正在使用的 $ PATH ,并确保您运行的是正确版本的perl。


    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.

    这篇关于Perl从cron.daily运行时找不到模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆