本文介绍了从cron运行casper.js脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图通过cron运行casper.js脚本。一切工作正常,当我手动运行脚本,但当我通过cron运行它得到以下错误:

I'm trying to run a casper.js script via cron. Everything works fine when I run the script manually, but when I run it via cron I get the following errors:

Traceback (most recent call last):
 File "/usr/local/bin/casperjs", line 46, in <module>
   status = subprocess.call(CASPER_COMMAND)
 File "/usr/lib/python2.6/subprocess.py", line 480, in call
   return Popen(*popenargs, **kwargs).wait()
 File "/usr/lib/python2.6/subprocess.py", line 633, in __init__
   errread, errwrite)
 File "/usr/lib/python2.6/subprocess.py", line 1139, in _execute_child
   raise child_exception
OSError: [Errno 2] No such file or directory

我的crontab条目是:

My crontab entry is:

30 9 * * * / usr / local / bin / casperjs lib / fsaupload.js arg1 arg2 arg3

我也试过了

30 9 * * * python / usr / local / bin / casperjs lib / fsaupload.js arg1 arg2 arg3

这给了我相同的结果。有任何想法吗?我想这可能是一个路径问题,但不知道从哪里去!

Which gives me the same result. Any ideas? I'm guessing it might be a path issue, but no idea where to go from here!

推荐答案

您应该使用绝对路径到您的casper脚本,例如:

You should probably use an absolute path to your casper script, something like:

30 9 * * * /usr/local/bin/casperjs /absolute/path/to/lib/fsaupload.js arg1 arg2 arg3


$ b b

我的两分钱。

My two cents.

编辑

是有点傻。您还可以通过设置 PHANTOMJS_EXECUTABLE 环境变量来设置 phantomjs 可执行文件的自定义路径:

Okay, it was a bit silly. You can also set a custom path to the phantomjs executable by setting the PHANTOMJS_EXECUTABLE environment variable:

$ export PHANTOMJS_EXECUTABLE="/path/to/phantomjs"

然后像往常一样运行脚本:

Then run your script as usual:

/usr/local/bin/casperjs /absolute/path/to/lib/fsaupload.js arg1 arg2 arg3

提示:如果您的crontab作为另一个

Hint: If your crontab runs as another user, check that it has access to the phantomjs path.

希望它有助于(和工作)。

Hope it helps (and works).

再次编辑

等待,您收到的堆栈跟踪说,您使用的是旧版本的CasperJS(例如 subprocess 模块不再使用)。尝试使用更新版本:)

Wait, the stack trace you get says you're using an old version of CasperJS (eg. the subprocess module is no more used). Try with a more recent version :)

这篇关于从cron运行casper.js脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 09:17