gpt4 book ai didi

Python 脚本不在 cron 下运行,尽管在手动运行时工作

转载 作者:可可西里 更新时间:2023-11-01 11:47:44 24 4
gpt4 key购买 nike

我知道有很多关于此的问题,但我已经尝试了一段时间但没有成功。我有一个简单的 python 测试脚本,它创建一个带有时间戳名称的文件夹。当我手动运行它时它工作得很好,但是当我尝试将它放入 crontab 时没有任何反应。知道我在这里搞砸了吗?这是脚本:(位于/home/ec2-user/cronscripts)

from subprocess import call
from time import time
import math

call(["mkdir","derp" +str(math.floor(time()))])

crontab -l 产生输出

* * * * * python /home/ec2-user/cronscripts/testscript.py

我也试过将“root”放入命令中,但没有成功。我也尝试过在脚本文件中显式设置 PATH 变量。

From root@domU-12-31-38-00-AC-02.compute-1.internal  Wed Jun 15 19:57:01 2011
Return-Path: <root@domU-12-31-38-00-AC-02.compute-1.internal>
Received: from domU-12-31-38-00-AC-02.compute-1.internal (localhost [127.0.0.1])
by domU-12-31-38-00-AC-02.compute-1.internal (8.14.4/8.14.4) with ESMTP id p5FJv1aS006094
for <root@domU-12-31-38-00-AC-02.compute-1.internal>; Wed, 15 Jun 2011 19:57:01 GMT
Received: (from root@localhost)
by domU-12-31-38-00-AC-02.compute-1.internal (8.14.4/8.14.4/Submit) id p5FJv1Dc006093;
Wed, 15 Jun 2011 19:57:01 GMT
Date: Wed, 15 Jun 2011 19:57:01 GMT
Message-Id: <201106151957.p5FJv1Dc006093@domU-12-31-38-00-AC-02.compute-1.internal>
From: root@domU-12-31-38-00-AC-02.compute-1.internal (Cron Daemon)
To: root@domU-12-31-38-00-AC-02.compute-1.internal
Subject: Cron <root@domU-12-31-38-00-AC-02> usr/bin/python /home/ec2-user/cronscripts/testscript.py
Content-Type: text/plain; charset=UTF-8
Auto-Submitted: auto-generated
X-Cron-Env: <SHELL=/bin/sh>
X-Cron-Env: <HOME=/root>
X-Cron-Env: <PATH=/usr/bin:/bin>
X-Cron-Env: <LOGNAME=root>
X-Cron-Env: <USER=root>

/bin/sh: usr/bin/python: No such file or directory

这是我在根邮件中找到的最后一个条目。它似乎无法找到 python,即使它正是它所说的位置。当我打印 crontab -l 时,usr/bin/python 确实有一个前导斜杠。我需要在某处更改 cron 路径吗?

最佳答案

对 crontab 中的所有命令使用完全限定路径。

0 */2 * * * /full/path/to/python /home/ec2-user/cronscripts/testscript.py

此外,所有字段都是 *?您预计什么时候运行?上面的示例每隔一小时运行一次。

关于Python 脚本不在 cron 下运行,尽管在手动运行时工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6363023/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com