简体   繁体   English

记录 cron 作业运行的管理命令的 output

[英]Logging the output of a management command run by a cron job

I have a cron job scheduled that runs a custom management command in Django.我有一个计划在 Django 中运行自定义管理命令的 cron 作业。 I would like to output all information on a success as well as a fail.我想 output 的所有信息都成功和失败。 How would I structure this?我将如何构建它?

CRONJOBS = [
    ('* * * * *', 'django.core.management.call_command', ['my_custom_command'])
]

I've tried setting up a relative path in settings like this我试过在这样的设置中设置相对路径

log_file_path = os.path.join(BASE_DIR, "log_files/cronjob.log")

and then tried the following 3 configurations but none of them worked然后尝试了以下 3 种配置,但都没有奏效

CRONJOBS = [
    ('* * * * *', 'django.core.management.call_command >> log_file_path', ['my_custom_command'])
]
CRONJOBS = [
    ('* * * * *', 'django.core.management.call_command', ['my_custom_command', '>> log_file_path'])
]
CRONJOBS = [
    ('* * * * *', 'django.core.management.call_command', ['my_custom_command >> log_file_path'])
]

I could also be structuring my relative path incorrectly but I've tried all of this with absolute paths as well.我也可能错误地构建了我的相对路径,但我也用绝对路径尝试了所有这些。

I figured out the answer to this.我想出了这个问题的答案。 The format that I used to set up the cron job requires an object before the log output path.我用来设置 cron 作业的格式要求在日志 output 路径之前有一个 object。

CRONJOBS = [
    ('* * * * *', 'django.core.management.call_command', ['my_custom_command'], {}, '>> log_file_path')
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM