Django cronjob 没有 运行

Django cronjob not running

我正在尝试通过自定义 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 实际上是 运行(正如我所想),因为日志是这样说的。

但是我在 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