0

I just want to run a cronjob every 2 and half hour time gaps, I tried 30 */2 * * * but this not working, any idea how to do this?

moonkotte
  • 3,661
  • 2
  • 10
  • 25
uvindu sri
  • 264
  • 1
  • 4
  • 16
  • 2
    There's no simple expressoin to describe this period. The easiest solution would be to run your script every 30 minutes, then have the script check the elapsed time since the last run and only run when the elapsed time >= 2.5 hours. – larsks Aug 23 '21 at 12:48
  • Thanks for the replay @larsks, I'm need to set this value in pipeline yaml file, I have a periodic pipeline to run, so I'm not sure I will be able to do this – uvindu sri Aug 23 '21 at 13:05
  • 3
    Another suggestion (Not a direct solution) is to run 2 cronjobs, both running every 5 hours. But the first one starts at 00:00, and the second starts at 02:30. By combining both, we get, jobs running every 2.5 hours. – Arutsudar Arut Aug 23 '21 at 14:25
  • Does this answer your question? [Schedule a cronjob to run every 2 1/2hours](https://stackoverflow.com/questions/45913424/schedule-a-cronjob-to-run-every-2-1-2hours) – Krzysztof Madej Aug 23 '21 at 15:53
  • Still I'm not sure what is the correct way, I can not run 2 jobs, need a way to find run only one job within 2.5 hours period – uvindu sri Aug 23 '21 at 17:03

1 Answers1

0

Posting this as a community wiki, feel free to edit and expand.


As it was pointed out in comments, it's not possible to setup cronjob with simple expression to run every 2.5 hours.

Workaround is to have two separate jobs which run every 5 hours.

Or as you mentioned in comments that you can't have two jobs, then as @larsks said you will need to implement some logic in your script:

The easiest solution would be to run your script every 30 minutes, then have the script check the elapsed time since the last run and only run when the elapsed time >= 2.5 hours.

Please find some already asked and answered questions about this topic:

moonkotte
  • 3,661
  • 2
  • 10
  • 25