Loading... --- title: crontab post: 2021-12-4 tags: [crontab, 任务, 定时] --- 目录说明 `/var/spool/cron/` 每个用户包括 root 的 crontab 任务,每个任务以创建者的名字命名 `/etc/crontab` 这个文件负责调度各种管理和维护任务。 `/etc/cron.d/` 这个目录用来存放任何要执行的 crontab 文件或脚本。 `/etc/cron.hourly|/etc/cron.daily|/etc/cron.weekly|/etc/cron.monthly` 每小时/天/星期、月执行一次 操作符作用 `*` 取值范围内的所有数字 `/` 每过多少个数字 `-` 从X到Z `,` 散列数字 注意事项 - 新创建的 cron 任务,不会马上执行,至少要过 2 分钟后才可以,当然你可以重启 cron 来马上执行。 - 所有命令需要写成绝对路径形式,如: /usr/local/bin/docker - 命令的默认目录为家目录 - 在 shell 脚本开头使用以下代码以导入环境变量 ```sh #!/bin/sh . /etc/profile . ~/.bash_profile ``` 或使用 ```sh 20 03 * * * . /etc/profile;/bin/sh /var/www/runoob/test.sh ``` 命令 ```sh crontab -e # 编辑 crontab -r # 删除目前的时程表 crontab -l # 列出目前的时程表 ``` 日程表说明 ```sh f1 f2 f3 f4 f5 program min hour day_in_month month day_in_week program 0-59 0-23 1-31 1-12 0-6 # examples ## 每一分钟执行一次 /bin/ls * * * * * /bin/ls ## 在 12 月内, 每天的早上 6 点到 12 点, ## 每隔 3 个小时 0 分钟执行一次 /usr/bin/backup: 0 6-12/3 * 12 * /usr/bin/backup ``` 最后修改:2022 年 01 月 18 日 06 : 30 PM © 允许规范转载 赞赏 如果觉得我的文章对你有用,请随意赞赏 赞赏作者 支付宝微信