diff --git "a/\347\216\213\345\217\213\351\221\253/20240617-\345\221\250\346\234\237\344\273\273\345\212\241\347\256\241\347\220\206.md" "b/\347\216\213\345\217\213\351\221\253/20240617-\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..f2297f1311398c6ad77d34fff4b4758d43f472ce --- /dev/null +++ "b/\347\216\213\345\217\213\351\221\253/20240617-\345\221\250\346\234\237\344\273\273\345\212\241\347\256\241\347\220\206.md" @@ -0,0 +1,71 @@ +# 周期任务管理 + +1、用户级Cron任务:每个用户都有自己的cron任务配置文件,位于/var/spool/cron/crontabs/username + +2、系统级Cron任务:位于/etc/crontab和/etc/cron.d + +3、周期性任务目录:这些目录包含在特定时间间隔运行的脚本 + +- /etc/cron.hourly/ +- /etc/cron.daily/ +- /etc/cron.weekly/ +- /etc/cron.monthly/ + +**编辑Cron任务** + +crontab -e + +**查看** + +crontab -l + +**删除所有Cron任务** + +crontab -r + +### Cron任务语法 + +```bash +* * * * * Comamand_to_execute +第一个*:分钟,0-59 +第二个*:小时,0-23 +第三个*:日期,1-31 +第四个*:月份,1-12 +第五个*:星期几,0-7 +``` + +例如:每天凌晨3点执行一个备份脚本 + +```bash +0 3 * * * /path/to/backup_scrip.sh +``` + +使用/etc/crontab + +该文件具有一个额外的字段用于指定运行任务的用户 + +```bash +17 * * * * root reboot +``` + +### 特殊符号 + +**1、星号(*):** + +​ 匹配任意值,每一 + +**2、逗号(,):** + +​ 指定一个任务列表,列出所有指定值 + +**3、短横线(-)** + +​ 指定一个范围值,开始-结尾 + +**4、斜杠(/)** + +​ 指间隔 + + **5、L(Last):** + +​ 表示最后一个 \ No newline at end of file