diff --git "a/45\351\253\230\351\233\205\350\257\227/20240615_\345\221\250\346\234\237\344\273\273\345\212\241\347\256\241\347\220\206.md" "b/45\351\253\230\351\233\205\350\257\227/20240615_\345\221\250\346\234\237\344\273\273\345\212\241\347\256\241\347\220\206.md" new file mode 100644 index 0000000000000000000000000000000000000000..abee42a75cacdf032074ab3178e8b2f207681232 --- /dev/null +++ "b/45\351\253\230\351\233\205\350\257\227/20240615_\345\221\250\346\234\237\344\273\273\345\212\241\347\256\241\347\220\206.md" @@ -0,0 +1,53 @@ +# 周期任务管理 + +​ ----计划任务 + +=> 提供一种可以重复的指定重复周期的一种机制,一种执行机制分类 + +1. 系统级 + + /etc/cron.hourly/(每小时要执行) + /etc/cron.daily/(每天要执行) + /etc/cron.weekly/(每星期要执行) + /etc/cron.monthly/(每月要执行) + +2. 用户级 + + /var/spool/cron/用户名 + +3. 全局配置 + + /etc/crontab + +### crontab + +``` +* * * * * command +分 时 天 月 周 命令 +``` + +命令格式: + +``` +编辑 + crontab -e [-u 用户名] +查看 + crontab -l [-u 用户名] +删除 + crontab -r [-u 用户名] + +``` + +特殊符号: + +``` +*: + 匹配范围内任意时间 +,: + 表示多个不连续的时间点 +-: + 表示连续的时间范围 +/n: + 指定时间频率,每n... +``` + diff --git "a/45\351\253\230\351\233\205\350\257\227/20240615_\345\221\250\346\234\237\344\273\273\345\212\241\347\273\203\344\271\240.md" "b/45\351\253\230\351\233\205\350\257\227/20240615_\345\221\250\346\234\237\344\273\273\345\212\241\347\273\203\344\271\240.md" new file mode 100644 index 0000000000000000000000000000000000000000..093af14d2b8d8efa454e25a8706914e150d794da --- /dev/null +++ "b/45\351\253\230\351\233\205\350\257\227/20240615_\345\221\250\346\234\237\344\273\273\345\212\241\347\273\203\344\271\240.md" @@ -0,0 +1,134 @@ +### 周期任务练习 + +执行在家目录touch a.txt + +``` +gaoyashi@iZf8zh6micauwcw30jcu5tZ:~$ crontab -e +no crontab for gaoyashi - using an empty one + +Select an editor. To change later, run 'select-editor'. + 1. /bin/nano <---- easiest + 2. /usr/bin/vim.basic + 3. /usr/bin/vim.tiny + +Choose 1-3 [1]: 2 +crontab: installing new crontab +``` + + + +1. 每天3:00执行一次 + + ``` + 0 3 * * * /home/touch a.txt + ``` + +2. 每周六2:00执行 + + ``` + 0 2 * * 6 /home/touch a.txt + ``` + +3. 每周六1:05执行 + + ``` + 05 1 * * 6 /home/touch a.txt + ``` + +4. 每周六1:25执行 + + ``` + 25 1 * * 6 /home/touch a.txt + ``` + +5. 每天8:40执行 + + ``` + 40 8 * * * /home/touch a.txt + ``` + +6. 每天3:50执行 + + ``` + 50 3 * * * /home/touch a.txt + ``` + +7. 每周一到周五的3:40执行 + + ``` + 40 3 * * 1-5 /home/touch a.txt + ``` + +8. 每周一到周五的3:41开始,每10分钟执行一次 + + ``` + 41/10 3 * * 1-5 /home/touch a.txt + ``` + +9. 每天的10:31开始,每2小时执行一次 + + ``` + 31 10/2 * * * /home/touch a.txt + ``` + +10. 每周一到周三的9:30执行一次 + + ``` + 30 9 * * 1-3 /home/touch a.txt + ``` + +11. 每周一到周五的8:00,每周一到周五的9:00执行一次 + + ``` + 0 8,9 * * 1-5 /home/touch a.txt + ``` + +12. 每天的23:45分执行一次 + + ``` + 45 23 * * * /home/touch a.txt + ``` + +13. 每周三的23:45分执行一次 + + ``` + 45 23 * * 3 /home/touch a.txt + ``` + +14. 每周一到周五的9:25到11:35、13:00到15:00之间,每隔10分钟执行一次 + + ``` + 25-35/10 9-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分别执行一次 + + ``` + 30,50 8 * * 1-5 /home/touch a.txt + 30 9 * * 1-5 /home/touch a.txt + 30,00 10-11,14 * * 1-5 /home/touch a.txt + 30 13 * * 1-5 /home/touch a.txt + ``` + +16. 每天16:00、10:00执行一次 + + ``` + 00 16,10 * * * /home/touch a.txt + ``` + +17. 每天8:10、16:00、21:00分别执行一次 + + ``` + 10 8 * * * /home/touch a.txt + 00 16,21 * * /home/touch a.txt + ``` + +18. 每天7:47、8:00分别执行一次 + + ``` + 47 7 * * * /home/touch a.txt + 00 8 * * * /home/touch a.txt + ``` + + \ No newline at end of file