Search code examples
pythonpython-3.xcroncron-task

Multiple jobs using python-crontab


I am using python-crontab to build a Desktop notification system. However, I can not figure out how to schedule multiple scripts using python-crontab.

Here is what I have to schedule one script:

my_user_cron  = CronTab(user=True)
job=my_user_cron.new(command='usr/bin/python3 /Users/Desktop/script.py', comment='script')
job.setall(* * * * *)
my_user_cron.write()

If anyone knows how to schedule multiple scripts using this library, please let me know. If you need more information or have any questions, feel free to ask.


Solution

  • See if this helps :

    
    cron = CronTab(user='username')
    
    job1 = cron.new(command='python example1.py')
    
    job1.hour.every(2)
    
    job2 = cron.new(command='python example1.py')
    job2.every(2).hours()
    
    for item in cron:
        print item
    
    cron.write()