From 194945e596105f68da30cdc19636e87b978bc5ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E5=80=A9=E5=80=A9?= <2294221913@qq.com> Date: Sun, 16 Jun 2024 22:27:06 +0800 Subject: [PATCH] crontab --- ...240616_\345\221\250\346\234\237crontab.md" | 169 ++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 "41 \351\231\210\345\200\251\345\200\251/20240616_\345\221\250\346\234\237crontab.md" diff --git "a/41 \351\231\210\345\200\251\345\200\251/20240616_\345\221\250\346\234\237crontab.md" "b/41 \351\231\210\345\200\251\345\200\251/20240616_\345\221\250\346\234\237crontab.md" new file mode 100644 index 0000000..ce50dc0 --- /dev/null +++ "b/41 \351\231\210\345\200\251\345\200\251/20240616_\345\221\250\346\234\237crontab.md" @@ -0,0 +1,169 @@ +## 周期任务管理crontab + +##### 概念 + +提供了一种可以重复的、指定重复周期的一种机制,一种执行机制 + +##### crontab定时任务 : 分、时、日、月、周 + +#### 语法 + +- 分钟 0-59 +- 小时 0-23 +- 天 1-31 +- 月份 1-12 +- 星期 0-7 +- 特殊字符: + - 星号(*):表示匹配任意值。例如,* 在分钟字段中表示每分钟都执行。 + - 逗号(,):用于分隔多个值。例如,1,3,5 在小时字段中表示 1 点、3 点和 5 点执行。 + - 斜线(/):用于指定间隔值。例如,*/5 在分钟字段中表示每 5 分钟执行一次。 + - 连字符(-):用于指定范围。例如,10-20 在日期字段中表示从 10 号到 20 号。 + - 问号(?):仅用于日期和星期几字段,表示不指定具体值。通常用于避免冲突 + + +#### 分类 + +- ##### 系统级 + + - /etc/cron.hourly + + - /etc/cron.weekly + + - /etc/cron.daily + + - /etc/cron.monthly + + - /etc/cron.yearly + +- ##### 用户级 + + - /var/spool/cron/crontabs/root //root用户的周期任务 + + - 用户配置选项 + + - -e 编辑 + + - -l 列出 + + - -r 删除 + +##### 周期任务练习 + +执行在家目录touch a.txt + +1. 每天3:00执行一次 + + ```bash + 0 3 * * * /home/touch a.txt + ``` + +2. 每周六2:00执行 + + ```bash + 0 2 * * 6 /home/touch a.txt + ``` + +3. 每周六1:05执行 + + ```bash + 5 1 * * 6 /home/touch a.txt + ``` + +4. 每周六1:25执行 + + ```bash + 25 1 * * 6 /home/touch a.txt + ``` + +5. 每天8:40执行 + + ```bash + 40 8 * * * /home/touch a.txt + ``` + +6. 每天3:50执行 + + ```bash + 50 3 * * * /home/touch a.txt + ``` + +7. 每周一到周五的3:40执行 + + ```bash + 40 3 * * 1-5 /home/touch a.txt + ``` + +8. 每周一到周五的3:41开始,每10分钟执行一次 + + ```bash + 41/10 3 * * 1-5 /home/touch a.txt + ``` + +9. 每天的10:31开始,每2小时执行一次 + + ```bash + 31 10/2 * * * /home/touch a.txt + ``` + +10. 每周一到周三的9:30执行一次 + + ```bash + 30 9 * * 1-3 /home/touch a.txt + ``` + +11. 每周一到周五的8:00,每周一到周五的9:00执行一次 + + ```bash + 0 8,9 * * 1-5 /home/touch a.txt + ``` + +12. 每天的23:45分执行一次 + + ```bash + 45 23 * * * /home/touch a.txt + ``` + +13. 每周三的23:45分执行一次 + + ```bash + 45 23 * * 3 /home/touch a.txt + ``` + +14. 每周一到周五的9:25到11:35、13:00到15:00之间,每隔10分钟执行一次 + + ```bash + 25,35,45,55 9 * * 1-5 /home/touch a.txt + 5-59/10 10 * * 1-5 /home/touch a.txt + 5,15,25,35 11 * * 1-5 /home/touch a.txt + */10 13-15 * * 1-5 /home/touch a.txt + ``` + +15. 每周一到周五的8:30、8:50、9:30、10:00、10:30、11:00、11:30、13:30、14:00、14:30、5:00分别执行一次 + + ```bash + 30,50 8 * * 1-5 /home/touch a.txt + 30 9,10,11,13,14 * * 1-5 /home/touch a.txt + 0 10,11,14,5 * * 1-5 /home/touch a.txt + ``` + +16. 每天16:00、10:00执行一次 + + ```bash + 0 16,10 * * * /home/touch a.txt + ``` + +17. 每天8:10、16:00、21:00分别执行一次 + + ```bash + 10 8 * * * /home/touch a.txt + 0 16,21 * * * /home/touch a.txt + ``` + +18. 每天7:47、8:00分别执行一次 + + ```bash + 47 7 * * * /home/touch a.txt + 0 8 * * * /home/touch a.txt + ``` + + \ No newline at end of file -- Gitee