cron 文件中的 * * * * *(五个星号)是什么意思?

Tho*_*day 67 solaris cron

旧 crontab 文件中的第一个非注释行以五个星号开头:

* * * * * ([a_command]) >/dev/null 2>&1
Run Code Online (Sandbox Code Playgroud)

作者已经走了,所以我不知道他们的意图全通配符对 (Solaris 8) cron 意味着什么? 这里的赌注要么运行一次,要么连续运行,要么永不运行,不幸的是,这很广泛。

如果您想知道前面的注释行,那就是“不要删除”。

注意:此 cron 文件正在运行。这个问题不是关于损坏的 cron 文件或需要故障排除的 cron 文件的问题的重复。

Luk*_*ame 61

每个月的每周的每一天的每一分钟,该命令都会运行。

man 5 crontab有这方面的文档。如果您只是键入man crontab,您将获得 crontab命令的文档。您需要的是手册页的第 5 部分,其中涵盖了包括该/etc/crontab文件在内的系统配置文件。为了将来参考,这些部分在man man

   1   Executable programs or shell commands
   2   System calls (functions provided by the kernel)
   3   Library calls (functions within program libraries)
   4   Special files (usually found in /dev)
   5   File formats and conventions eg /etc/passwd
   6   Games
   7   Miscellaneous  (including  macro  packages and conven?
       tions), e.g. man(7), groff(7)
   8   System administration commands (usually only for root)
   9   Kernel routines [Non standard]
Run Code Online (Sandbox Code Playgroud)

  • +1 为答案,-1 为`man cron` 评论。众所周知,“手册”页对于初学者来说难以阅读和理解——这就是人们来到这里向他们解释“手册”页的原因。 (12认同)
  • 没关系,只要用户知道 5 甚至相关。大多数新的或兼职的 Linux 用户不知道使用哪个编号(如果有)来访问手册页。 (6认同)
  • 完全是因为它应该是`man 5 crontab`。该联机帮助页更具体且易于理解。见:http://linux.die.net/man/5/crontab (4认同)
  • @John,为了证明你的观点,作为一个只在我需要重新启动偶尔的 apache 服务器时才将脚趾伸入 *nix 的人,我什至不知道你可以做一个“man 5”,我不知道如果我做了... (3认同)

Moh*_*sal 44

*= 总是。它是 cron 调度表达式每个部分的通配符。

所以,* * * * *手段every minuteevery hourevery dayevery monthevery dayweek

 * * * * *  command to execute
 ? ? ? ? ?
 ? ? ? ? ?
 ? ? ? ? ?
 ? ? ? ? ?????? day of week (0 - 7) (0 to 6 are Sunday to Saturday, or use names; 7 is Sunday, the same as 0)
 ? ? ? ??????????? month (1 - 12)
 ? ? ???????????????? day of month (1 - 31)
 ? ????????????????????? hour (0 - 23)
 ?????????????????????????? min (0 - 59)
Run Code Online (Sandbox Code Playgroud)

上面漂亮的图是维基百科提供的

另一个例子:

0 * * * *- 这意味着 cron 将始终在分钟0(每小时)
0 1 * * *时运行 - 这意味着 cron 将始终在 1 点钟运行。
* 1 * * *- 这意味着当小时为 1 时,cron 将每分钟运行一次。所以1:00, 1:01, ... 1:59


小智 11

First star = Minutes: 0-59
Second star = Hours: 0-23
Third star = Day of Month: 0 - 31
Fourth star = Month: 0 - 12
Fifth star = Day of Week: 0 - 6 (0 means sunday)
Run Code Online (Sandbox Code Playgroud)

假设你想每个月的 1 号运行一些东西。

0 0 1 * * something.sh
Run Code Online (Sandbox Code Playgroud)

  • 这意味着每月 1 日每小时每小时运行一些内容(即第一天运行 1440 次)。 (2认同)