1

I need to run cron job every 3 hours after the start of job. Currently I am using

0 */3 * * *

If I start job now according to my time at 2:45 PM this command will complete its first interval at 3:00 PM and next interval at 6 PM. I want to complete my first interval exactly after 3 hours like if i start job at 2:45 PM my interval should complete at 5:45 PM. How I can achieve that? Thanks

2 Answers2

1

Use:

45 2,5,8,11,14,17,20,23 * * *

see: https://crontab.guru/#45_2,5,8,11,14,17,20,23_*_*_*

Luuk
  • 12,245
  • 5
  • 22
  • 33
  • oops, I have done from `2:45 AM` ..... – Luuk Mar 19 '23 at 09:58
  • Yeah, that's the only way I can think of. Cron doesn't know when you "start running cron", it operates only on absolute values – Maxim Mazurok Mar 19 '23 at 09:58
  • What you could do is to create a script that would be triggered by corn every minute and it will remember when it first started, save last run into local file, read that file and only perform action if that time was 3h before current time – Maxim Mazurok Mar 19 '23 at 10:00
0

Cron doesn't know when you "start running cron", it operates only on absolute values

What you could do is create a script that would be triggered by corn every minute and it will remember when it first started, save the last run into a local file, read that file, and only perform the action if that time was 3h before the current time

Maxim Mazurok
  • 3,856
  • 2
  • 22
  • 37