Do these cron expressions match?

Is there any difference between

*/5 * * * * <COMMAND> 

and

 0/5 * * * * <COMMAND> 

?

+1
source share
1 answer

This is not the same.

  • The first will be executed every 5 minutes, starting at any moment, and
  • the second will be executed in minutes 0, 5, 10, ... 55.

Only if the first runs at 5k minute for the first time will they have the same behavior.


Every 5 minutes can be written as follows:

 0,5,10,15,20,25,30,35,40,45,50,55 * * * * <COMMAND> 

this is

 0/5 * * * * <COMMAND> 

or

 */5 * * * * <COMMAND> 

In any case, the latter will be launched at any time when the changes will be minutes, and then save a distance of 5 minutes to the next execution.


The symbol * means everyone . If he is alone, it will mean every minute, every hour, etc.

The symbol / can be used to indicate incrementing values. If we specify X/Y , it means that every Y minutes starts with a minute X.

  • 0/15 = every 15th minute of the hour, starting from minute 0 = 0,15,30,45
  • 3/20 = every 20 minutes of the hour, starting at minute three = 3,23,43
  • /40 = every 40th minute of the hour = 40
  • 3/40 = every 40th minute of the hour, starting at minute three = 43

Returning to your question, using both operators gets the following result:

*/5 = every 5 minutes, starting at any time. Thus, it will start whenever the minute changes and repeats after 5 minutes, 10, etc.

0/5 = every 5 minutes, starting from minute 0. It will be considered internal: 0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, since these are minutes that satisfy the + condition 5 minutes starting at minute 0.


Some links:

+3
source

All Articles