Search code examples
python-3.xcroncron-task

Does cron monitor exit codes for a job, I have a cron job that is getting restarted


I have a cron job set to run a python script say script.py, I have set the cron to run it every 6 hours. The issue is that when the script is getting run, it keeps starting the process again and again. The python script has a few sleeps in it. Technically the script runs and exits when run standalone. For some reason I see the cron trying to start the process again and again.

* */6 * * * python3 /path/to/script.py

I have read answers on using locks and pid files, asking this just to understand the behaviour.


Solution

  • I think that your problem is not that your job is getting restarted after terminating, it will be executed every minute. If you enter a ´*´ this stands for every possible value. So when you enter EVERY VALUE for your minutes, your task is getting executed every minute. Instead, you should use:

    0 */6 * * * python3 /path/to/script.py
    

    Hope this solves your problem