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

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

问题描述

我有使用 Net::Finger 的 perl 程序,并且在 Fedora 11 中从 cron.daily 成功运行.
我刚刚将服务器升级到 Fedora 18,这些相同的 perl 程序不再从 cron 运行,而是在以 root 身份登录时从命令行正常运行.
错误是:

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 .)

模块的路径是 /root/perl5/lib/perl5/Net/Finger.pm 但我不知道如何在不引起更多错误的情况下添加路径.提前致谢.

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.

以下是将任意目录添加到 Perl 的模块搜索路径的三种方法.

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

  1. 设置PERL5LIB环境变量

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

  • 使用-I命令行开关

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

  • 在 perl 脚本中使用 lib 编译指示

    #! /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.

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

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