0

I use following code to schedule a task, but the Crontab entry it produces is in wrong format.

def main(): 
   from crontab import CronTab
   cron = CronTab(user=True)
   job = cron.new(command='python /home/niroshan/repos/maisie/Tests/dummyprint.py')
   job.minute.on(2)
   cron.write()

When I execute crontab -e I can see following crontab entry, but the script does not get called.

2 * * * * python /home/niroshan/repos/maisie/Tests/dummyprint.py

After some googling I manually changed the entry to look like below and it started working.

*/2 * * * * python /home/niroshan/repos/maisie/Tests/dummyprint.py

How do I get python to create the entry in correct format?

Niroshan
  • 1,974
  • 6
  • 32
  • 55

1 Answers1

0

Use this instead:

job.minute.every(2)

on triggers the command 'on' the minute, i.e. 1:02, 2:02, etc.

Alex Hall
  • 31,431
  • 4
  • 39
  • 71