加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 从cron运行casper.js脚本

发布时间:2020-12-14 01:22:30 所属栏目:Linux 来源:网络整理
导读:我正在尝试通过cron运行casper.js脚本.当我手动运行脚本时,一切正常,但是当我通过cron运行它时,我得到以下错误: Traceback (most recent call last): File "/usr/local/bin/casperjs",line 46,in module status = subprocess.call(CASPER_COMMAND) File "/u
我正在尝试通过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

这给了我相同的结果.有任何想法吗?我猜它可能是路径问题,但不知道从哪里开始!

解决方法

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

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

我的两分钱.

编辑:

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

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

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

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

提示:如果您的crontab以另一个用户身份运行,请检查它是否可以访问phantomjs路径.

希望它有所帮助(并且有效).

再次编辑

等等,你得到的堆栈跟踪说你正在使用旧版本的CasperJS(例如,不再使用子进程模块).尝试使用更新的版本:)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读