Cron Expression Structure

工具型软件cron是一款类Unix的操作系统下的基于时间的任务管理系统。用户们可以通过cron在固定时间、日期、间隔下,运行定期任务(可以是命令和脚本)。cron常用于运维和管理,但也可用于其他地方,如:定期下载文件和邮件。cron该词来源于希腊语chronos(χρόνος),原意是时间。

cron表达式结构

一般形式

/ 第一位 第二位 第三位 第四位 第五位
内容 分钟 小时 星期
取值范围 0-59 0-23 1-31 1-12 0-6(周日为0)(如果不确定填?)
月也可以写成JAN,FEB,MAR,APR,MAY,JUN,JUL,AUG,SEP,OCT,NOV,DEC。
星期也可以写成SUN,MON,TUE,WED,THU,FRI,SAT。
注意,范围必须为int整数。

特殊形式

有一些地方会用到,比起一般形式没有秒和年,其余一样

/ | 第一位 | 第二位 | 第三位 | 第四位 | 第五位
—|—|—|—|—|–|–|–
内容 | 分钟 | 小时 | 日 | 月 | 星期
取值范围|0-59|0-23|1-31|1-12|0-6(周日为0)(如果不确定填?)|1970-2099

通配符

cron表达式结构所有值,所有形式一般均支持通配符。

/ 含义
* 任何。例如填在月份里,就是每个月的意思
/ 整除,第一个值表开始的时间,第二个是除数。例如在秒里填上1-20,1,21,41,1,21,41这样轮下去。
- 周期,第一个值表开始,第二个结束。例如在月份里填上1-4,就是1,2,3,4这四个月。
, 列举。例如在月份里填上4,6,7,8,就是4,6,7,8这四个月。

在线Cron表达式解释生成

https://cron.qqe2.com/

Cron is a time-based job scheduling utility on Unix-like operating systems. Users can use cron to run scheduled tasks (which can be commands or scripts) at fixed times, dates, or intervals. Cron is commonly used in operations and maintenance but can also be applied elsewhere, such as regularly downloading files or sending emails. The term “cron” derives from the Greek word “chronos” (χρόνος), meaning time.

Cron Expression Structure

General Form

/ First Position Second Position Third Position Fourth Position Fifth Position
Content Minute Hour Day Month Weekday
Value Range 0-59 0-23 1-31 1-12 0-6 (Sunday as 0) (Use ? if uncertain)
Months can also be written as JAN, FEB, MAR, APR, MAY, JUN, JUL, AUG, SEP, OCT, NOV, DEC.
Weekdays can also be written as SUN, MON, TUE, WED, THU, FRI, SAT.
Note: Ranges must be integer values (int).

Special Form

Used in some contexts. Compared to the general form, it lacks seconds and years; the rest is the same.

/ First Position Second Position Third Position Fourth Position Fifth Position
Content Minute Hour Day Month Weekday
Value Range 0-59 0-23 1-31 1-12 0-6 (Sunday as 0) (Use ? if uncertain)

Wildcards

All values in cron expression structures and all forms generally support wildcards.

/ Meaning
* Any. For example, if placed in the month field, it means every month.
/ Division. The first value indicates the start time, and the second is the divisor. For example, in the seconds field, filling in 1-20 cycles as 1, 21, 41, 1, 21, 41, and so on.
- Range. The first value indicates the start, and the second indicates the end. For example, in the month field, filling in 1-4 means January, February, March, and April.
, Enumeration. For example, in the month field, filling in 4,6,7,8 means April, June, July, and August.

Online Cron Expression Interpreter & Generator

https://cron.qqe2.com/


Cron Expression Structure
https://tokisaki.top/blog/cron-expressions/
作者
Tokisaki Galaxy
发布于
2021年2月28日
许可协议