如何使用 modulepython-crontab 从 crontab 行获取 crontab 计划?
How do you obtain the crontab schedule from a crontab line using the modulepython-crontab?
我有以下 cron 文件 (cron.txt):
03 09,17 * * * script1
03 08 * * * script2
00 08,11,14,17 * * * script3
00 20 * * * script4
00 07 1 * * script6767
并且我想在 Python 2.7 中编写一段代码来打印:
您的脚本 "script1" 将 运行 在“03 09,17 * * *”(我将使用 croniter 将 cron 翻译成人类语言)。
使用下面的代码:
from crontab import CronTab
file_cron = CronTab(tabfile='cron.txt')
for linie in file_cron:
comanda = linie.command
print comanda
我在 crontab 中打印将 运行 的脚本或命令,当我遍历 crontab 行时很好,但我如何打印时间?
CronTab 是否有任何内置方法可以帮助我做到这一点?就像我上面用 linie.command 做的那样?
我想要这样的东西:
variable = linie.get_the_damn_cron_time
print variable
output: 03 09,17 * * *
我该怎么做?
这些值存储在一个名为 'slices' 的结构中,您可以像这样直接将其转换为字符串:
for job in cron:
print unicode(job.slices)
我有以下 cron 文件 (cron.txt):
03 09,17 * * * script1
03 08 * * * script2
00 08,11,14,17 * * * script3
00 20 * * * script4
00 07 1 * * script6767
并且我想在 Python 2.7 中编写一段代码来打印: 您的脚本 "script1" 将 运行 在“03 09,17 * * *”(我将使用 croniter 将 cron 翻译成人类语言)。
使用下面的代码:
from crontab import CronTab
file_cron = CronTab(tabfile='cron.txt')
for linie in file_cron:
comanda = linie.command
print comanda
我在 crontab 中打印将 运行 的脚本或命令,当我遍历 crontab 行时很好,但我如何打印时间? CronTab 是否有任何内置方法可以帮助我做到这一点?就像我上面用 linie.command 做的那样? 我想要这样的东西:
variable = linie.get_the_damn_cron_time
print variable
output: 03 09,17 * * *
我该怎么做?
这些值存储在一个名为 'slices' 的结构中,您可以像这样直接将其转换为字符串:
for job in cron:
print unicode(job.slices)