为什么我的Perl脚本在由cron运行时加载模块? [英] Why can't my Perl script load a module when run by cron?

查看:221
本文介绍了为什么我的Perl脚本在由cron运行时加载模块?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一堆Perl脚本,它们都运行良好,但需要使用Plibdata; 向上。



我设置了一个运行的cron作业(我收到来自root的确认电子邮件),并返回以下错误消息:

 无法在@INC中找到Plibdata.pm(@INC包含:/ install / lib /opt/perl58/lib/5.8.8/IA64.ARCHREV_0-thread-multi /opt/perl58/lib/5.8.8 /opt/perl58/lib/site_perl/5.8.8/IA64.ARCHREV_0-thread-multi /opt/perl58/lib/site_perl/5.8.8 / opt / perl58 / lib / site_perl。)在./x第5行。

BEGIN失败 - 编译在./x第5行中止。

5 is ... you guessed it .... use Plibdata;



我也试图设置环境:

 使用lib$ ENV {CARSPATH} / install / lib 

所以也许如果我找到这个plibdata的位置, p>

我的cron命令将使用 / usr / bin / sh 执行crontabs ...



有任何建议吗?



此脚本可以从命令行运行。

解决方案

从其他人建议的包装脚本运行程序可能是我的首选方法,但可能有一些其他解决方案:



如果你使用现代cron,你可以在你的crontab条目中做这样的事情:

  * * * * CARSPATH = / opt / carsi x 

以适当的时间表指示符替换星号。 >

这将为x进程设置CARSPATH,并允许使用通过环境变量的lib语句。



也可以根据您的shell和cron实现,将您的环境设置存储在一个文件中,并执行以下操作:

  * * * * source specialenv.sh&& x 

其中specialenv.sh包含(如bash)行

  export CARSPATH = / opt / carsi 

您也可以直接在crontab中设置环境变量,如果您选择这样做。


I have a bunch of Perl scripts that all run fine, yet need to have use Plibdata; up top.

I set up a cron job that runs (I get the confirmation email from root) and it spits back the following error message:

Can't locate Plibdata.pm in @INC (@INC contains: /install/lib /opt/perl58/lib/5.8.8/IA64.ARCHREV_0-thread-multi /opt/perl58/lib/5.8.8 /opt/perl58/lib/site_perl/5.8.8/IA64.ARCHREV_0-thread-multi /opt/perl58/lib/site_perl/5.8.8 /opt/perl58/lib/site_perl .) at ./x line 5.

BEGIN failed--compilation aborted at ./x line 5.

Line 5 is... you guessed it.... use Plibdata;

I am also attempting to set the environment as such:

use lib "$ENV{CARSPATH}/install/lib";

so maybe if I found the location of this plibdata, I could explicitly direct it that way?

My cron commands will be executed using /usr/bin/sh says crontabs...

Any suggestions?

This script works from the command line.

解决方案

Running your program from a wrapper script as others have suggested is probably my preferred method, but there may be a few other solutions:

If you're using a modern cron you may be able to do something like this in your crontab entry:

* * * * * CARSPATH=/opt/carsi x

replacing the asterisks with the appropriate schedule designators.

This will set CARSPATH for the x process and allow the use lib statement that passes the environment variable to work.

You can also, depending on your shell and cron implementation, store your environment setup in a file and do something like:

* * * * * source specialenv.sh && x

Where specialenv.sh contains lines like (for bash)

export CARSPATH=/opt/carsi

You may also be able to set environment variables directly in the crontab, should you choose to do so.

这篇关于为什么我的Perl脚本在由cron运行时加载模块?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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