Przeglądaj źródła

补充定时任务命令

nick 8 lat temu
rodzic
commit
e0004f98ab
1 zmienionych plików z 22 dodań i 1 usunięć
  1. 22 1
      crontab.md

+ 22 - 1
crontab.md

@@ -1,5 +1,17 @@
 #### crontab 命令
 
+Linux下的任务调度分为两类:系统任务调度和用户任务调度。
+
+系统任务调度:系统周期性所要执行的工作,比如写缓存数据到硬盘、日志清理等。在 `/etc` 目录下有一个 `crontab` 文件,这个就是系统任务调度的配置文件。
+
+用户任务调度:用户定期要执行的工作,比如用户数据备份、定时邮件提醒等。
+
+`/etc/cron.deny`     该文件中所列用户不允许使用 crontab 命令,默认不存在
+
+`/etc/cron.allow`    该文件中所列用户允许使用 `crontab` 命令,默认不存在
+
+`/var/spool/cron/`   所有用户 `crontab` 文件存放的目录,以用户名命名
+
 ```
 crontab -l #显示定时任务列表
 
@@ -49,4 +61,13 @@ Select an editor.  To change later, run 'select-editor'.
 * 2,3 * * * ~/http.sh #每天凌晨2点,3点 执行一次 ~/http.sh shell 文件
 
 10 * * * 1-5 root /usr/local/bin/php /home/ubuntu/demo.php #周一到周五第10分钟以 root 用户 php 命令去执行一次 demo.php 文件
-```
+
+01 * * * * root run-parts /etc/cron.hourly #每小时第1分钟执行 /etc/cron.hourly 目录内的脚本
+```
+
+run-parts 参数指定的目录必须是以下任意一个,其他位置的目录无法执行
+
+- /etc/cron.hourly  小时
+- /etc/cron.daily   每天
+- /etc/cron.weekly  每周
+- /etc/cron.monthly 每月