Perl脚本工作,但不通过CRON [英] Perl script works but not via CRON

查看:112
本文介绍了Perl脚本工作,但不通过CRON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个perl脚本(可以同步到wp):


  1. 通过shell运行

  2. 不通过cron运行(我没有得到错误)

我唯一能想到的是它读取配置文件错误,但它是通过完整路径(我想)定义。



我读取我的配置文件为:

  my $ config = Config :: Simple-> import_from('/ home / 12345 / data / scripts / delicious / wpds.ini',
\my%config);

(我托管在mediatemple上)





更新1 :HERE是完整的代码: http://plugins.svn.wordpress.org/wordpress-23-compatible-wordpress-delicious-daily-synchronization-script / trunk / (但我已将上述路径添加到配置文件位置作为差异)



更新2 :crossposted上 https://forums.mediatemple.net/viewtopic.php?pid=31563# p31563



更新3 :完整路径可以解决问题

解决方案

cron作业和从shell运行的作业之间的区别是environment。主要的区别是,您的配置文件等不是为cron作业运行的,因此您在正常shell环境中设置的任何环境变量在cron环境中设置不相同 - 没有PATH的扩展,没有环境变量标识哪里美味和/或WP托管等。



建议:创建一个cron作业,只是报告环境到一个已知的文件:

  env> /home/27632/tmp/env.27632 

然后看看你自己的shell环境中设置了什么比较。



其他的环境差异是cron作业没有终端,输入和输出都有/ dev / null - 所以互动的东西不能很好地工作。


I have a perl script (which syncs delicious to wp) which:

  1. runs via the shell but
  2. 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

解决方案

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:

env > /home/27632/tmp/env.27632

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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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