Is the following cron expression every 45 minutes?

I want to run the script every 45 minutes (and not: the 45th minute of every hour)

eg. 10:00, 10:45, 11:30, 12:15, etc.

*/45 * * * * 

Not sure if this is the correct expression.

+12
cron
Jan 25 '13 at 8:10
source share
2 answers

I suspect (I’m editing now: I’m sure) that he doesn’t do what you want: the fields are separate, and */45 for minutes is no more than 0,45 . I would use the following three entries if */45 not doing the job:

 0,45 0-23/3 * * * 30 1-23/3 * * * 15 2-23/3 * * * 

If you look at the entry.c file in vixie cron sources, you will notice that each field of each record is analyzed by get_list and presented as bitmap images of valid values ​​for this field. This almost eliminates any “smart” interpretation, since at this stage the difference between */45 and 0,45 is lost ... but there is a MIN_STAR flag set in the presence of * in minutes (including */45 ). So, take a look at cron.c , one place where MIN_STAR being MIN_STAR to find out that this is not related to our problem. Now we know for sure that */45 means "every 45 minutes of every hour": 0:00, 0:45, 1:00, 1:45, etc.

There were two answers that confidently stated the opposite, citing an unsuccessful passage in the manual:

The steps are also allowed after the asterisk, so if you want to say "every two hours" just use "* / 2"

We are fortunate that we have a 24-hour day containing an even number of hours, making "every two hours from 0:00 every day" and "every two hours in general" indistinguishable. It is unfortunate that management did not go far enough to document non-trivial cases, giving the impression that * */22 means every 22 hours. Is not. A star with a step is simply a reduction of the list of values ​​in the field where it was used; It does not interact with other fields.

+13
Jan 25 '13 at 8:28
source share

With a basic cron time, your system checks once a minute to see if there are any cronjobs to run. He will look at your crontab, and if it is time to run, then he will run! But every 45 minutes is an interval that will always be at the 15-minute mark on the dial. for example, starting from zero, the first is 0:45. Next will be 90 minutes from zero or 1:30, and the next will be 2:15 ... so easily you can see that the time for each instance that you want to execute is script, the minute hand will be at 12, 3, 6 or 9 If you run your script every 15 minutes and check the hour to see if it is correct, you can execute your script. You are probably using either a table, or you can use the modulo function. Hurrah!

0
Oct 10 '17 at 17:10
source share



All Articles