django - Django cronjob 没有运行
问题描述
我正在尝试从自定义 Django 命令创建一个 cronjob。当我手动运行命令时,它运行良好。正是我想要的。唯一的事情是,我希望它安排好(一天两次)。但是当我输入完全相同的命令时crontab -e
它不起作用?有什么建议么?
crontab -e:
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h dom mon dow command
* * * * * /usr/bin/python3 /home/marvin/VulnScanner/manage.py pentest 3
仅运行此命令可以正常工作:
/usr/bin/python3 /home/marvin/VulnScanner/manage.py pentest 3
解决方案
好的,我找到了解决方案。crontab 实际上正在运行(正如我所说的那样),因为 te log 是这样说的。
但是我在我的 python 文件中使用了一个可执行文件,而 crontab 找不到。这必须与默认情况下 crontab 没有 PATH 的情况有关。用户 shell 会在路径中查找可执行文件。crontab 没有。您可以通过在 crontab 顶部添加来解决此问题:
PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
我已将此附加到我的 cronjob 中,以获取我的 python 脚本的输出:
>> /home/user/cronlog.log 2>&1
推荐阅读
- azure - Azure Function Consumption 静默流式传输大文件错误 500
- scala - 无法在 spark 中读取镶木地板文件:java.lang.NoSuchMethodError: org.json4s.jackson.JsonMethods
- python - 什么可能导致此错误:FileNotFoundError:[Errno 2] 没有这样的文件或目录
- c++ - C++ 数组编译
- python-3.x - 如何在指定时间内没有传入连接的情况下关闭 CherryPy?
- javascript - 如何在 jQuery 中编写 document.getElementsByClassName(names)[n]
- javascript - 围绕对象方法调用的 IF 安全检查
- python - 如何使用 SQLAlchemy 查询 MutableDict 列中的嵌套数组字段?
- python-3.x - 为什么如果没有中断,这段代码会一直返回我的输入?
- java - Paypal 返回网址不适用于沙盒帐户