Cesar Cesar - 5 months ago 31
Linux Question

Set a cron in advanced time logic Linux

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.


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.