Freddy Tan
Freddy Tan

Reputation: 59

Are these cron expression valid?

I'm trying to learn the cron expression, but I'm pretty confused by few corner cases.
I've tried to test them on few online validator and even tried python-crontab module, but they gave the different result which make me more confused.
Would someone explain the following cron expressions? Or any good way to validate a cron expression?

Online validator I tried:

  1. http://cron.schlitt.info/
  2. http://cronchecker.net/
  3. http://www.cronmaker.com/

the cron expressions need explanation,

59-5/5 * *   *   *
1/2    * *   *   *
0      0 1/2 *   *
0      0 *   6/2 *

Upvotes: 0

Views: 1284

Answers (1)

kranteg
kranteg

Reputation: 1001

I would say no, these cron expressions are not valid.

You shouldn't use them because you are not sure of what they do. I've tried that one 1/2 * * * * command and it works but not as I thank. I thought it will work as 1 * * * * command and it worked as 1-59/2 * * * * command.

Perhaps some of these works but I repeat you shouldn't use them. The crontab manpage is clear enough to use range and step values in a good way :

 Ranges of numbers are allowed.  Ranges are two numbers separated with a
 hyphen.  The specified range is inclusive.  For example, 8-11 for an ``hours''
 entry specifies execution at hours 8, 9, 10 and 11.

 Lists are allowed.  A list is a set of numbers (or ranges) separated by com-
 mas.  Examples: ``1,2,5,9'', ``0-4,8-12''.

 Step values can be used in conjunction with ranges.  Following a range with
 ``/<number>'' specifies skips of the number's value through the range.  For
 example, ``0-23/2'' can be used in the hours field to specify command execu-
 tion every other hour (the alternative in the V7 standard is
 ``0,2,4,6,8,10,12,14,16,18,20,22'').  Steps are also permitted after an aster-
 isk, so if you want to say ``every two hours'', just use ``*/2''.

So when you use ranges, you have to specified two numbers separated with a hyphen. The range have to be like first-last so if you wanna do 50-15, use comma and prefer 50-59,0-15

If you want to use step values, they have to follow a range.

Don't make it harder than it is. It will be easier for guys who will have to read your work.

Upvotes: 1

Related Questions