1

I know how to set up a cron which calls a script every 2 minutes. For example:

 */2 * * * *

But now I would like it to run only from 9.30 to 9.45, again every 2 minutes. What is the syntax for that purpose? I have tried with

*/2 9.30-9.45 * * *

but, obviously, it is not working.

Cesar
  • 514
  • 1
  • 5
  • 16
  • 1
    You need to run it at 9:30, 9:32, 9:34, etc.: http://stackoverflow.com/questions/5200551/how-to-set-a-cron-job-to-run-at-a-exact-time – José Luis Oct 11 '16 at 09:34
  • 1
    We built crontab.guru to help with syntax issues like this. Here is what it says for the accepted answer: "At every 2nd minute from 30 through 45 past hour 9" http://crontab.guru/#30-45/2_9_%2A_%2A_%2A – HeyZiko Oct 11 '16 at 16:01
  • @HeyZiko: That's pretty cool! – tmt Oct 14 '16 at 12:03
  • I thought that you could pass human readable condition to be converted directly but do not know how to do it. – Cesar Oct 14 '16 at 12:43

1 Answers1

2

In your particular case you can use:

30-45/2 9 * * * [command]

For more complex setups I think it's generally better to move the logic into a script that Cron would call every N minutes and that would check the time and exit immediately if the current time is not within the defined range.

tmt
  • 7,611
  • 4
  • 32
  • 46