-1

I'm trying to use Python-crontab module over Linux OS (CentOS 7)

My config file is as follows:

{
  "ossConfigurationData": {  
    "work1": [
      {   
        "cronInterval": "0 0 0 1 1 ?",      
        "attribute": [
          {             
            "rules": [
                {
                    ......
                }
               ]               
            }
            ],
    "work2": [
      {   
        "cronInterval": "0 0 0 1 2 ?",      
        "attribute": [
          {             
            "rules": [
                {
                    ......
                }
               ]               
            },
            ]
      }

}

The file contain many work items. Each work item has it own cron expression. I want my Python script to be able to schedule each cron separately, set it in my OS & run it. When running, the purpose is running each work item separately according to it cron expression I did step-by-step according to this tutorial. After many tests it's writing the cron, but I'm not sure it's what I need

Using this module, I can't create reference to the relevant work item. It's just adding a new line to the OS crontab with any execution I want to put there. I can't describe what I wish to run (i.e. - work1 or work2)

Any suggestions?

10x in advance :)

Community
  • 1
  • 1
Aviv Cohen
  • 69
  • 6
  • Possible duplicate of [Running crontab with python](https://stackoverflow.com/questions/18513562/running-crontab-with-python) – stovfl Oct 28 '18 at 11:24
  • @stovfl: That link you said is a duplicate is about running Python programs on a schedule configured in cron. This question is about configuring cron using a Python program. – John Zwinck Oct 28 '18 at 11:33
  • "Nothing works" is never an adequate problem description. Show us the code you tried and tell us exactly what happened when you ran it. – John Zwinck Oct 28 '18 at 11:33
  • ***"but nothing works"***: Whera are the differents between running a **Python Script** or **any executable**, the **Cron** setup is the same. [Edit] your Question and explain your **nothing works**. – stovfl Oct 28 '18 at 11:49
  • According to the [GitLab repo](https://gitlab.com/doctormo/python-crontab/commits/master) and the [pypi sumary](https://pypi.org/project/python-crontab/), this module is still supported. And of course not, it is not limited to Ubuntu distro. – TGrif Oct 28 '18 at 11:55
  • @JohnZwinck I've added information to my question – Aviv Cohen Oct 29 '18 at 09:38

1 Answers1

0

A common error is not using the cron.save() function after editing. Given the limited information in the question, this is the most likely answer.

  • Hi @Martin - I'm not using cron.save(). I'll try to be more clear - I have Json config file that contain many **work items**. Each work item has it own cron expression. I want my Python script to be able to schedule each cron separately, set it in my OS & run it, when the cron occur, with the content of the specific work item. – Aviv Cohen Oct 29 '18 at 09:14
  • Hi Aviv, What you're describing isn't a problem in the `python-crontab` module, but some connection between the json and your crontab. I don't understand enough about your codebase to know why it's not working. It should and what you're asking for is reasonable. Alsa something isn't right. – Martin Owens -doctormo- Nov 05 '18 at 01:29
  • Hi @Martin. I've updated my original question with code sample. Pls. take a look – Aviv Cohen Nov 06 '18 at 09:05