当前位置:网站首页>Cron(Crontab)--use/tutorial/example
Cron(Crontab)--use/tutorial/example
2022-08-05 04:12:00 【IT Knives Out】
原文网址:Cron(Crontab)--使用/教程/实例_IT利刃出鞘的博客-CSDN博客
简介
说明
本文介绍CronThe use of the regular expression.
在线工具
quartz/Cron/Crontab表达式在线生成工具-BeJSON.com
quartz/Cron/Crontab表达式在线生成工具-pcwanli.com
概述
格式
Cron表达式是一个字符串,字符串以5或6个空格隔开,分为6或7个域,每个域代表一个含义,Cron有如下两种格式:
- Seconds Minutes Hours DayofMonth Month DayofWeek Year
- Seconds Minutes Hours DayofMonth Month DayofWeek
Cron缺点
只能在某一个域的值到达指定数字后才会运行任务,无法立刻运行.比如:想要从现在开始,每小时运行一次,是做不到的,对于这个需求,Cron只能做到按指定时间运行,例如0 0 * * * * ?:1:00:00, 2:00:00, 3:00:00 ...
(如果有哪位大佬有用Cron解决这个需求的方法请评论)
示例
每个元素可以是一个值(如:6), 一个连续区间(如:9-12), 一个间隔时间(如:8-18/4)(/4表示每隔4小时), 一个列表(如:1,3,5), 通配符.
含义 | 表达式 |
每隔5秒执行一次 | */5 * * * * ? |
每隔1分钟执行一次 | 0 */1 * * * ? 或者0 * * * * * |
每隔1小时执行一次 | 0 0 * * * * ? |
每天23:00:00执行一次 | 0 0 23 * * ? |
每个星期三中午12点 | 0 0 12 ? * WED |
周一至周五的上午10:15触发 | 0 15 10 ? * MON-FRI |
每月1号凌晨1:00:00执行一次 | 0 0 1 1 * ? |
每月最后一天23:00:00执行一次 | 0 0 23 L * ? |
Monthly bottom first2天23:00:00执行一次 | 0 0 23 L-1 * ? |
| The last Tuesday of each month do a | 0 0 23 ? * 3L |
每周星期天凌晨1:00:00实行一次 | 0 0 1 ? * L |
在26分、29分、33分执行一次 | 0 26,29,33 * * * ? |
2002-2006年的每个月的最后一个星期五上午10:15执行 | 0 15 10 ? 6L 2002-2006 |
朝九晚五工作时间内每半小时 | 0 0/30 9-17 * * ? |
每月最后一日的上午10:15触发 | 0 15 10 L * ? |
每月的最后一个星期五上午10:15触发 | 0 15 10 ? * 6L |
每月的第三个星期五上午10:15触发 | 0 15 10 ? * 6#3 |
字段的取值
字段 | 允许值 | 允许的特殊字符 |
秒(Seconds) | 0~59的整数 | , - * / 四个字符 |
分(Minutes) | 0~59的整数 | , - * / 四个字符 |
小时(Hours) | 0~23的整数 | , - * / 四个字符 |
日期(DayofMonth) | 1~31的整数(需要考虑月的天数) | ,- * ? / L W C 八个字符 |
月份(Month) | 1~12的整数或者 JAN-DEC | , - * / 四个字符 |
星期(DayofWeek) | 1~7的整数或者 SUN-SAT (1=SUN) | , - * ? / L C # 八个字符 |
年(Year)(可选) | 1970~2099 | , - * / 四个字符 |
符号的含义
符号 | 说明 |
* | 表示匹配该域的任意值.假如在Minutes域使用*, 即表示每分钟都会触发事件. |
? | 只能用在DayofMonth和DayofWeek两个域.它也匹配域的任意值,但实际不会.因为DayofMonth和DayofWeek会相互影响.例如想在每月的20日触发调度,不管20日到底是星期几,则只能使用如下写法: 13 13 15 20 * ?, 其中最后一位只能用?,而不能使用*,如果使用*表示不管星期几都会触发,实际上并不是这样. |
- | 表示范围.例如在Minutes域使用5-20,表示从5分到20分钟每分钟触发一次 |
/ | 表示起始时间(/的左侧)与间隔时间(/的右侧).开始触发,然后每隔固定时间触发一次. 例如:Minutes域中:“0/15”表示从0分开始,每15分钟一次.“3/20”表示从3分开始,每20分钟一次(与“3,23,43”等效) |
, | 表示列出枚举值.例如:在Minutes域使用5,20,则意味着在5分和20分都触发一次. |
L | 单词“last”的缩写.只能出现在DayofMonth和DayofWeek域. L用于DayofMonth域:表示当月最后一天,倒数第n天的写法:L-n+1.比如倒数第3天:L-2 L用于DayofWeek域:表示最后一个周六,倒数第nThe week value method:L-n+1.Such as last week2:3L |
W | 表示工作日(周一到周五),只能出现在DayofMonth域.指定离指定日的最近的一个平日. 如果5日是星期六,则将在最近的工作日:星期五,即4日触发. 如果5日是星期天,则在6日(周一)触发; 如果5日在星期一到星期五中的一天,则就在5日触发. |
LW | 某个月最后一个工作日,即最后一个星期五. |
# | 每个月第几个星期几,只能出现在DayofWeek域.例如:4#2,表示某月的第二个星期三. |
C | 代表“Calendar”的意思.它的意思是计划所关联的日期,如果日期没有被关联,则相当于日历中所有日期. 例如5C在日期字段中就相当于日历5日以后的第一天.1C在星期字段中相当于星期日后的第一天. |
参考网址
边栏推荐
- [Paper Notes] MapReduce: Simplified Data Processing on Large Clusters
- Bytebuffer put flip compact clear method demonstration
- how to measure distance from point to face in creo
- UE4 在游戏运行时更改变量 (通过鼠标滑轮来更改第一人称角色的最大行走速度)
- 【背包九讲——01背包问题】
- bytebuffer use demo
- UE4 第一人称角色模板 添加蹲伏功能
- 事件解析树Drain3使用方法和解释
- Industry Status?Why do Internet companies prefer to spend 20k to recruit people rather than raise their salary to retain old employees~
- 开发属于自己的node包
猜你喜欢

银行数据采集,数据补录与指标管理3大问题如何解决?

Industry Status?Why do Internet companies prefer to spend 20k to recruit people rather than raise their salary to retain old employees~

bytebuffer internal structure

Swing有几种常用的事件处理方式?如何监听事件?

程序开发的一些常规套路(一)

Increasing leetcode - a daily topic 1403. The order of the boy sequence (greed)
![[CISCN2019 South China Division]Web11](/img/15/843334fec0a5cc8cfaba92aab938db.png)
[CISCN2019 South China Division]Web11

The test salary is so high?20K just graduated
![[SWPU2019]Web1](/img/06/36e69a2d7d5475a6749a7d81edf50f.png)
[SWPU2019]Web1

The most effective seven performance testing techniques of software testing techniques
随机推荐
Dive into how it works together by simulating Vite
Use CH341A to program external Flash (W25Q16JV)
Detailed and comprehensive postman interface testing practical tutorial
数据库设计的酸(ACID)碱(BASE)原则
There are several common event handling methods in Swing?How to listen for events?
bytebuffer put flip compact clear 方法演示
多御安全浏览器新版下载 | 功能优秀性能出众
动力小帆船制作方法简单,电动小帆船制作方法
In the WebView page of the UI automation test App, the processing method when the search bar has no search button
Cron(Crontab)--使用/教程/实例
七夕节代码表白
4T硬盘剩余很多提示“No space left on device“磁盘空间不足
多御安全浏览器 V10.8.3.1 版正式发布,优化多项内容
Haproxy搭建Web群集
什么是ASEMI光伏二极管,光伏二极管的作用
token, jwt, oauth2, session parsing
[SWPU2019]Web1
No regrets, the appium automation environment is perfectly built
Growth-based checkerboard corner detection method
bytebuffer 内部结构