Here is the scenario:- I want to run a specific function in my NodeJs application and for that i am using NodeScheduler
I know i can use this expression
*/3 8-15 * * *
for every 3 minutes between 8 AM to 3 PM but i want to run it between 8:30 AM to 3:15 PM but Cron expression for this which i made is certainly wrong
30-15/3 8-15 * * *
does anyone know what can be correct cron expression for this scenario ?
The normal
crondoesn't give you that level of expressiveness but there's nothing stopping you from putting further restrictions in the command portion of the entry:This will actually run the
cronjob itself every three minutes between 8am and 4pm, but the payload (your script that does the actual work) will only be called if the current time is between 8:30am and 3:15pm.The placing of
1in front of the time is simply a trick to avoid issues treating numbers starting with zero as octal.In fact, I have a script
withinTime.shthat proves useful for this sort of thing:With this script in your path, you can simplify the
croncommand a little: