使用python_crontab计划的作业不工作

2024-09-26 22:12:36 发布

您现在位置:Python中文网/ 问答频道 /正文

我使用下面的python代码来调度ubuntu中的作业。在

from crontab import CronTab
cron = CronTab(user='username')
job  = cron.new(command='/usr/bin/python3 /home/(user)/Desktop/Schedular/ScheduleInvoicingUtility.py >> /home/(user)/Desktop/Schedular/Logs.txt')
job.setall('*/2 * * * *')        
cron.write()
print(cron.render())

代码运行成功,其呈现函数print输出如下:

^{pr2}$

但不知道这个作业保存在ubuntu中的什么地方,而且作业在指定的时间后没有运行/工作。在

你知道我做错什么了吗?在


Tags: 代码fromimporthomeubuntu作业job调度
1条回答
网友
1楼 · 发布于 2024-09-26 22:12:36

最后,我用一些小的改动来解决这个问题。下面是从python正确创建cron作业的代码:

cron = CronTab(user=True)
job  = cron.new(comment='My_Unique_Job', command='/usr/bin/python3 /home/(user)/Desktop/Schedular/ScheduleInvoicingUtility.py >> /home/(user)/Desktop/Schedular/Logs.txt')
job.setall('*/2 * * * *')
cron.write()

使用此选项可删除以前具有相同id的作业

^{pr2}$

完整代码为:

^{3}$

别忘了导入CronTab:

from crontab import CronTab

使用pip安装python_crontab。在

pip install python_crontab

相关问题 更多 >

    热门问题