Perl 脚本可以工作,但不能通过 CRON
我有一个perl脚本(它与wp同步):
- 通过shell运行但
- 不通过cron运行(并且我没有收到错误)
我唯一能想到的是它错误地读取了配置文件但是..它是通过完整路径定义的(我认为)。
我将我的配置文件读为:(
my $config = Config::Simple->import_from('/home/12345/data/scripts/delicious/wpds.ini',
\my %config);
我托管在 mediatemple 上)
有人知道吗?
更新1:这是完整的代码:http://plugins.svn.wordpress.org/wordpress-23-兼容-wordpress-delicious-daily-synchronization-script/trunk/ (但我已将路径添加为上面的配置文件位置作为差异)
更新 2:交叉发布在 https://forums.mediatemple.net/viewtopic.php?pid=31563#p31563
更新3:完整路径解决了问题
I have a perl script (which syncs delicious to wp) which:
- runs via the shell but
- does not run via cron (and i dont get an error)
The only thing I can think of is that it read the config file wrongly but... it is defined via the full path (i think).
I read my config file as:
my $config = Config::Simple->import_from('/home/12345/data/scripts/delicious/wpds.ini',
\my %config);
(I am hosted on mediatemple)
Does anybody have a clue?
update 1: HERE is the complete code: http://plugins.svn.wordpress.org/wordpress-23-compatible-wordpress-delicious-daily-synchronization-script/trunk/ (but I have added the path as above to the configuration file location as difference)
update 2: crossposted on https://forums.mediatemple.net/viewtopic.php?pid=31563#p31563
update 3: the full path did the trick, solved
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
cron 作业和从 shell 运行的作业之间的区别在于“环境”。主要区别在于您的配置文件等不是针对 cron 作业运行的,因此您在正常 shell 环境中设置的任何环境变量在 cron 环境中的设置都不相同 - 没有 PATH 扩展,没有标识位置的环境变量Delicious 和/或 WP 托管等。
建议:创建一个 cron 作业,简单地将环境报告给已知文件:
然后比较一下您自己的 shell 环境中设置的内容。很有可能,这会暴露出问题所在。
如果做不到这一点,其他环境差异是 cron 作业没有终端,并且有 /dev/null 用于输入和输出 - 所以交互式的东西不能很好地工作。
The difference between a cron job and a job run from the shell is 'environment'. The primary difference is that your profile and the like are not run for a cron job, so any environment variables you have set in your normal shell environment are not set the same in the cron environment - no extensions to PATH, no environment variables identifying where Delicious and/or WP are hosted, etc.
Suggestion: create a cron job that simply reports the environment to a known file:
Then see what is set in your own shell environment in comparison. Chances are, that will reveal the trouble.
Failing that, other environmental differences are that a cron job has no terminal, and has /dev/null for input and output - so interactive stuff does not work well.
看来问题不在于运行 perl,而在于找到
您应该尝试的配置库:
并在 cron 中运行类似的 perl 脚本,并读取输出
(它们可能不同)
it seems the problem is not in running perl, but locating the Config library
you should try:
and run a similar perl script in cron, and read the output
it possible that they differ
我建议查看我的答案 如何模拟环境 cron 执行脚本?
这是一个类似 Jonathan 的答案,但更进一步。
I suggest looking at my answer to How to simulate the environment cron executes a script with?
This is an similar Jonathan's answer but goes a bit further.
根据您的 crontab,并且根据您的安装,问题可能是“perl”。正如其他人指出的那样,cron 的环境,特别是
$PATH
变量是不同的。 perl 可能不在路径中,因此您需要在 cron 命令中输入 perl 的完整路径。您可以使用命令
$ type perl
确定路径Based on your crontab, and depending on your installation, the problem might be the "perl". As others note the environment, particularly the
$PATH
variable, is different for cron. perl may not be in the path so you need to put the full path to perl in the cron command.You can determine the path with the command
$ type perl
我遇到了同样的问题...
Perl 脚本可以工作,但不能通过 CRON =>错误:“perl:未找到命令”
...从 Plesk 12.0 更新到 Plesk 12.5 后。但现有的答案对我来说没有多大帮助。
这花了一些时间,但我在 Odin 论坛中找到了这个帖子,它对我有帮助: https://talk.plesk.com/threads/scheduled-tasks-always-fail.331821/
他们建议如下:
删除 /var/spool/cron/crontabs 文件中的行:
之后,我的 cron 作业运行时没有任何错误。
(Ubuntu 14.04 和 Plesk 12.5)
I run into the same problem ...
Perl script works but not via CRON => error: "perl: command not found"
... after an update from Plesk 12.0 to Plesk 12.5. But the existing answers were not very helpful for me.
It took some time, but than I found this thread in the Odin forum which helps me: https://talk.plesk.com/threads/scheduled-tasks-always-fail.331821/
They suggest the following:
That deletes in the /var/spool/cron/crontabs files the line:
After that, my cron jobs run with out any error.
(Ubuntu 14.04 with Plesk 12.5)