Perl 脚本有效但不能通过 CRON [英] Perl script works but not via CRON
问题描述
我有一个 perl 脚本(将美味同步到 wp):
I have a perl script (which syncs delicious to wp) which:
- 通过shell运行,但
- 不通过 cron 运行(而且我没有收到错误)
我唯一能想到的是它错误地读取了配置文件但是...它是通过完整路径定义的(我认为).
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);
(我在 mediatemple 上托管)
(I am hosted on mediatemple)
有人知道吗?
更新 1:这里是完整的代码:http://plugins.svn.wordpress.org/wordpress-23-compatible-wordpress-delicious-daily-synchronization-script/trunk/(但我添加了配置文件位置如上路径不同)
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)
更新 2:交叉发布在 https://forums.mediatemple.net/viewtopic.php?pid=31563#p31563
更新 3:完整路径成功了,解决了
update 3: the full path did the trick, solved
推荐答案
cron 作业和从 shell 运行的作业之间的区别在于环境".主要区别在于您的配置文件等不是针对 cron 作业运行的,因此您在普通 shell 环境中设置的任何环境变量在 cron 环境中都不同 - 没有对 PATH 的扩展,没有环境变量标识在哪里美味和/或WP托管等
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.
建议:创建一个简单的将环境报告给已知文件的 cron 作业:
Suggestion: create a cron job that simply reports the environment to a known file:
env > /home/27632/tmp/env.27632
然后对比下看看你自己的shell环境里设置了什么.很有可能,这会暴露问题.
Then see what is set in your own shell environment in comparison. Chances are, that will reveal the trouble.
否则,其他环境差异是 cron 作业没有终端,输入和输出具有/dev/null - 所以交互性的东西不能很好地工作.
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!