• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

Cronjob:找不到命令

用户头像
it1352
帮助1

问题说明

我的cronjob如下:

I have a cronjob that is the following:

*/10    *   *   *   *   root    cd /some/directory && python3 FILE.py >> Output.txt 2>&1

如果我从常规命令行运行该命令,它将正常工作.但是当从cronjob运行时,我得到/bin/sh:python3:找不到

if i run that command from a regular command line, it works fine. But when ran from cronjob, I get /bin/sh: python3: not found

但是当我运行 echo $ PATH 时,它会返回

But when I run echo $PATH it returns

/sbin:/bin:/usr/sbin:/usr/bin:/usr/syno/sbin:/usr/syno/bin:/usr/local/sbin:/usr/local/bin:/usr/local/python3/bin:/opt/bin

(请注意,此目录中包含/usr/local/python3/bin

(Note that /usr/local/python3/bin is included in this directory

我该如何解决?

正确答案

#1

cronjob的环境似乎与交互式shell不同.您可以编辑cronjob以使用绝对路径来调用该python脚本.或者,您可以编写wrapper sh脚本来准确设置python脚本所需的环境,然后让cronjob执行该脚本.

It seems like cronjob has a different environment than your interactive shell. You could edit the cronjob to use an absolute path to call that python script. Or you can write a wrapper sh script to setup exactly the environment required by the python script and have cronjob execute that.

https://askubuntu.com/questions/23009/reasons-why-crontab-不工作

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /reply/detail/tanhcffceg
系列文章
更多 icon
同类精品
更多 icon
继续加载