使用python-crontab仅运行一个cronjob [英] Running a cronjob only one using python-crontab

查看:154
本文介绍了使用python-crontab仅运行一个cronjob的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

from crontab import CronTab

tab = CronTab()
cmd1 = 'actual command'

cron_job = tab.new(cmd)
cron_job.minute.every(1)
cron_job.enable()
tab.write_to_user(user=True)

我尝试使用minutes.at(1)在第一分钟运行,但是我不知道在命令行上运行命令的正确方法是什么固定时间(上午6点),只有一次。。我知道每个最终都会重复一次,但是我不希望那样。需要说明的是,我需要使用python-crontab。

I have tried using minute.at(1) to run at the first minute, but I don't know whats the right way to run the command at a fixed time (6 am), just once.. I know "every" ends up repeating it, but I don't want that. The caveat is I need to use python-crontab.

推荐答案

crontab语法为: mm hh dd mt wd 。因此,将其设置为每天早上6点,将是 00 06 * * * ,表示每天,每月和工作日的06:00(24小时制)。如果我正确地引用了文档,则此方法应该有效:

The crontab syntax is: mm hh dd mt wd. So to set it to every morning at 6am it would be 00 06 * * * meaning 06:00 (24 hr time) of any day, month, weekday. If I'm referring to the documentation correctly, this should work:

from crontab import CronTab

tab = CronTab()
cmd1 = 'actual command'

cron_job = tab.new(cmd)
cron_job.setall('00 06 * * *')
cron_job.enable()
tab.write_to_user(user=True)

这篇关于使用python-crontab仅运行一个cronjob的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆