Linux 我在crontab中有一个与日程安排相关的问题

Linux 我在crontab中有一个与日程安排相关的问题,linux,cron,Linux,Cron,我正在尝试在centos中使用crontab。 如果我在cron选项卡中设置如下时间,它是如何工作的 * 5 * * * 摘自crontab手册页: The time and date fields are: field allowed values ----- -------------- minute 0-59 hour 0-23

我正在尝试在centos中使用crontab。 如果我在cron选项卡中设置如下时间,它是如何工作的

* 5 * * *

摘自crontab手册页:

   The time and date fields are:

          field          allowed values
          -----          --------------
          minute         0-59
          hour           0-23
          day of month   1-31
          month          1-12 (or names, see below)
          day of week    0-7 (0 or 7 is Sunday, or use names)

   A  field  may  contain  an  asterisk  (*),  which  always  stands   for
   "first-last".

   Ranges of numbers are allowed.  Ranges are two numbers separated with a
   hyphen.  The specified range is inclusive.  For example, 8-11 for an

   Lists are allowed.  A list is a set of numbers (or ranges) separated by
   commas.  Examples: "1,2,5,9", "0-4,8-12".

   Step  values can be used in conjunction with ranges.  Following a range
   with "/<number>" specifies skips of  the  number's  value  through  the
   range.  For example, "0-23/2" can be used in the 'hours' field to specâ
   ify command execution for every other hour (the alternative in  the  V7
   standard  is  "0,2,4,6,8,10,12,14,16,18,20,22").   Step values are also
   permitted after an asterisk, so if specifying a job to be run every two
   hours, you can use "*/2".

   Names  can  also be used for the 'month' and 'day of week' fields.  Use
   the first three letters of the particular day or month (case  does  not
   matter).  Ranges or lists of names are not allowed.

   The  "sixth"  field  (the rest of the line) specifies the command to be
   run.  The entire command portion of the line, up to a newline or a  "%"
   character, will be executed by /bin/sh or by the shell specified in the
   SHELL variable of the cronfile.  A "%" character in the command, unless
   escaped  with a backslash (\), will be changed into newline characters,
   and all data after the first % will be sent to the command as  standard
   input.

   Note:  The day of a command's execution can be specified in the followâ
   ing two fields â 'day of month', and 'day of week'.  If both fields are
   restricted  (i.e.,  do not contain the "*" character), the command will
   be run when either field matches the current time.  For example,
   "30 4 1,15 * 5" would cause a command to be run at 4:30 am on  the  1st
   and 15th of each month, plus every Friday.

   EXAMPLE CRON FILE
   # use /bin/sh to run commands, no matter what /etc/passwd says
   SHELL=/bin/sh
   # mail any output to `paul', no matter whose crontab this is
   MAILTO=paul
   #
   CRON_TZ=Japan
   # run five minutes after midnight, every day
   5 0 * * *       $HOME/bin/daily.job >> $HOME/tmp/out 2>&1
   # run at 2:15pm on the first of every month -- output mailed to paul
   15 14 1 * *     $HOME/bin/monthly
   # run at 10 pm on weekdays, annoy Joe
   0 22 * * 1-5    mail -s "It's 10pm" joe%Joe,%%Where are your kids?%
   23 0-23/2 * * * echo "run 23 minutes after midn, 2am, 4am ..., everyday"
   5 4 * * sun     echo "run at 5 after 4 every sunday"
时间和日期字段为:
字段允许值
-----          --------------
第0-59分钟
小时0-23
一月一日至三十一日
第1-12个月(或姓名,见下文)
第0-7周的某一天(0或7是星期日,或使用名称)
字段可能包含星号(*),它始终代表
“最后一个”。
允许数字的范围。范围是两个数字,用a分隔
连字符。指定的范围是包含的。例如,8-11表示
名单是允许的。列表是一组数字(或范围),由
逗号。例如:“1,2,5,9”,“0-4,8-12”。
阶跃值可与范围一起使用。跟随一系列
with“/”指定数字的值通过
范围例如,“0-23/2”可以在“小时”字段中用于规范
每隔一小时执行一次ify命令(V7中的替代方案
标准为“0,2,4,6,8,10,12,14,16,18,20,22”)。阶跃值也为
星号后允许,因此如果指定作业每两周运行一次
小时,您可以使用“*/2”。
“月份”和“星期几”字段也可以使用名称。使用
特定日期或月份的前三个字母(不包括大小写)
物质)。不允许使用名称的范围或列表。
“第六个”字段(行的其余部分)指定要执行的命令
跑行的整个命令部分,直到换行符或“%”
字符,将由/bin/sh或中指定的shell执行
cronfile的SHELL变量。命令中的“%”字符,除非
带反斜杠(\)的转义将更改为换行符,
第一个%之后的所有数据将作为标准发送到命令
输入。
注意:命令的执行日期可以在下面的
输入两个字段——“月的哪一天”和“周的哪一天”。如果两个字段都是
受限(即不包含“*”字符),命令将
在任一字段与当前时间匹配时运行。例如
“30 4 1,15*5”将导致在1日凌晨4:30运行命令
每月15号,再加上每周五。
CRON文件示例
#无论/etc/passwd说什么,都可以使用/bin/sh运行命令
SHELL=/bin/sh
#将任何输出发送到“paul”,无论这是谁的crontab
MAILTO=paul
#
CRON_TZ=日本
#每天午夜后跑五分钟
50***$HOME/bin/daily.job>>$HOME/tmp/out 2>&1
#每月一日下午2:15运行-输出邮件发送给paul
15 14 1**$HOME/bin/每月
#平日晚上10点跑步,惹恼乔
0 22**1-5邮件-s“现在是晚上10点”joe%joe,%%你的孩子在哪里?%
23 0-23/2***echo“每天凌晨2点、凌晨4点……后跑23分钟”
5 4**sun echo“每周日4点后5点跑步”

有很多现有工具可用于解释cron表达式,请参见例如。