Crontab

来自 ChinaUnix Wiki

Linux命令:crontab

功能说明:设置计时器。
语  法:crontab [-u <用户名称>][配置文件] 或 crontab [-u <用户名称>][-elr]
补充说明:cron是一个常驻服务,它提供计时器的功能,让用户在特定的时间得以执行预设的指令或程序。只要用户会编辑计时器的配置文件,就可以使用计时器的功能。其配置文件格式如下:
 Minute Hour Day Month DayOFWeek Command 

参  数: 
-e  编辑该用户的计时器设置。 
-l  列出该用户的计时器设置。 
-r  删除该用户的计时器设置。 
-u<用户名称>  指定要设定计时器的用户名称。


英文版本,欢迎翻译:

ABOUT CRONTAB

List of files that you want to run on a regular schedule.

SYNTAX

crontab [-e] [-l] [-r] [filename]

-e edit a copy of the current user's crontab file, or creates an empty file to edit if crontab does not exist. When editing is complete, the file is installed as the user's crontab file. If a user- name is given, the specified user's crontab file is edited, rather than the current user's crontab file; this may only be done by a super-user. The environment variable EDITOR determines which editor is invoked with the -e option. The default editor is ed. Note that all crontab jobs should be submitted using crontab ; you should not add jobs by just editing the crontab file because cron will not be aware of changes made this way. -l list the crontab file for the invoking user. Only a super-user can specify a username following the -r or -l options to remove or list the crontab file of the specified user. -r remove a user's crontab from the crontab filename The filename that contains the commands to run.


Lines that can be in the crontab file.

minute (0-59), hour (0-23), day of the month (1-31), month of the year (1-12), day of the week (0-6 with 0=Sunday).

EXAMPLES

crontab -e = edits the crontab file to be used.

0 12 14 2 * mailx john%Happy Birthday!%Time for lunch.

Below is a table that represents what each of the above fields are for. mon hour dayofmonth monthofyear dayofweek command 0 12 14 2 * mailx john%Happy Birthday!%Time for lunch.


Options Explanation

  • Is treated as a wild card. Meaning any possible value.
  • /5 Is treated as ever 5 minutes, hours, days, or months. Replacing the 5 with another numerical value will change this option.

2,4,6 Treated as an OR, so if placed in the hours, this could mean at 2, 4, or 6 o-clock. 9-17 Treats for any value between 9 and 17. So if placed in day of month this would be days 9 through 17. Or if put in hours it would be between 9 and 5.


If you wish to create a task to be performed once later during the day you may wish to consider using the at command.



个主工具