cron

  • cron: 服务名称

  • crond: 后台进程

  • crontab: 定制好的任务计划表

配置文件

  • /etc/crontab: 系统任务

  • /var/spool/cron下的文件: 用户任务

文件

说明

/etc/cron.deny

该文件中所列用户不允许使用crontab命令

/etc/cron.allow

该文件中所列用户允许使用crontab命令

/var/spool/cron/ or /var/spool/cron/crontabs

所有用户crontab文件存放的目录, 以用户名命名

查看用户定时任务

### 方法 1
bovenson@ThinkCentre:~$ crontab -l
no crontab for bovenson

### 方法 2
bovenson@ThinkCentre:~$ sudo cat /var/spool/cron/crontabs/bovenson
[sudo] bovenson 的密码:
# DO NOT EDIT THIS FILE - edit the master and reinstall.
# (/tmp/crontab.uOvisi/crontab installed on Mon Sep 11 20:32:49 2017)
# (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)
# Edit this file to introduce tasks to be run by cron.
# 
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
# 
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').# 
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
# 
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
# 
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
# 
# For more information see the manual pages of crontab(5) and cron(8)
# 
# m h  dom mon dow   command

任务格式

  • 在以上任何值中,星号(*)可以用来代表所有有效的值。譬如,月份值中的星号意味着在满足其它制约条件后每月都执行该命令。

  • 整数间的短线(-)指定一个整数范围。譬如,1-4 意味着整数 1、2、3、4。

  • 用逗号(,)隔开的一系列值指定一个列表。譬如,3, 4, 6, 8 标明这四个指定的整数

  • 正斜线(/)可以用来指定间隔频率。在范围后加上 /\ 意味着在范围内可以跳过 integer。譬如,0-59/2 可以用来在分钟字段定义每两分钟。间隔频率值还可以和星号一起使用。例如,*/3 的值可以用在月份字段中表示每三个月运行一次任务

  • 开头为井号(#)的行是注释,不会被处理

示例

配置任务

示例

最后更新于

这有帮助吗?