我正在尝试通过 cron 运行 casper.js 脚本。当我手动运行脚本时一切正常,但是当我通过 cron 运行它时出现以下错误:
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 条目是:
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
这给了我同样的结果。有任何想法吗?我猜这可能是一个path
问题,但不知道从这里去哪里!
您可能应该使用 casper 脚本的绝对路径,例如:
30 9 * * * /usr/local/bin/casperjs /absolute/path/to/lib/fsaupload.js arg1 arg2 arg3
我的两分钱。
Edit:
好吧,有点傻。您还可以设置自定义路径phantomjs
可执行文件通过设置PHANTOMJS_EXECUTABLE
环境变量:
$ export PHANTOMJS_EXECUTABLE="/path/to/phantomjs"
然后照常运行您的脚本:
/usr/local/bin/casperjs /absolute/path/to/lib/fsaupload.js arg1 arg2 arg3
提示:如果您的 crontab 以其他用户身份运行,请检查它是否有权访问 phantomjs 路径。
希望它有帮助(并且有效)。
再次编辑
等等,你得到的堆栈跟踪表明你正在使用旧版本的 CasperJS(例如subprocess
不再使用模块)。尝试使用更新的版本:)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)