AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 25898
Accepted
Bakhtiyor
Bakhtiyor
Asked: 2011-02-12 16:09:51 +0800 CST2011-02-12 16:09:51 +0800 CST 2011-02-12 16:09:51 +0800 CST

如何解释这个 crontab 命令?

  • 772

我知道如果我在crontab -e以下命令 中编写,01 04 * * * somecommand那么它将somecommand在每个月的每一天凌晨 4:01 运行。

如果我写了会发生什么* * * * * somecommand?它会somecommand每分钟运行一次吗?这种语法也可以吗?

并且可以使用这里@reboot解释的特殊字符串,如,@daily等。如果我写命令,将在一天中的什么时间执行?somecommand@daily somecommand

crontab
  • 2 2 个回答
  • 6618 Views

2 个回答

  • Voted
  1. Best Answer
    belacqua
    2011-02-12T16:43:32+08:002011-02-12T16:43:32+08:00

    这将每分钟运行一次您的命令。这是有效的语法。

    以下是来自的血腥细节info crontab:

            The first five fields  shall be integer patterns that specify the
            following:
    
            1. Minute [0,59]
    
            2. Hour [0,23]
    
            3. Day of the month [1,31]
    
            4. Month of the year [1,12]
    
            5. Day of the week ([0,6] with 0=Sunday)
    
           Each  of  these  patterns  can be either an asterisk (meaning all valid
           values), an element, or a list of elements separated by commas. An ele‐
           ment  shall  be  either  a  number or two numbers separated by a hyphen
           (meaning an inclusive range). The specification of days can be made  by
           two  fields  (day  of the month and day of the week).  If month, day of
           month, and day of week are all asterisks, every day shall  be  matched.
           If either the month or day of month is specified as an element or list,
           but the day of week is an asterisk, the month and day of  month  fields
           shall  specify  the days that match. If both month and day of month are
           specified as an asterisk, but day of week is an element or  list,  then
           only the specified days of the week match. Finally, if either the month
           or day of month is specified as an element or list, and the day of week
           is  also  specified as an element or list, then any day matching either
           the month and day of month, or the day of week, shall be matched.
    

    您链接到的文章看起来不错。它为您提供了一些很好的示例,实际上它比我在此处提供的手册页摘录更容易阅读。
    您应该能够使用它谈论的语法。

    根据我的 crontab,@daily 在 6:25 AM 运行。

    $ grep daily /etc/crontab 
    25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
    
    • 5
  2. theTuxRacer
    2011-02-13T01:40:17+08:002011-02-13T01:40:17+08:00

    您还可以通过在每列中使用正斜杠来指定奇数频率。

    * */2 * * * foo

    将foo在可被 2 整除的时间执行,即:12 AM、2 AM、4 AM、...、10 PM、12 AM。

    记住这个命令

    */1 * * * * env > /home/yourUser/env.out

    将在您的 crontab 中输出 crontab 环境的环境变量供您使用。您可以使用 ${HOME}、${SHELL} 等变量来使脚本更清晰,也可以在另一台机器上使用该脚本。

    • 3

相关问题

  • Cron 邮件通知

  • Cron.hourly 不会运行

  • 网络启动时如何运行cron作业?

  • 我的 cron.hourly 配置有什么问题?

  • 备份 bash 脚本未压缩其 tarball

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    我需要什么命令来解压缩/提取 .tar.gz 文件?

    • 8 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Marko Smith

    如何使用命令行将用户添加为新的 sudoer?

    • 7 个回答
  • Marko Smith

    更改文件夹权限和所有权

    • 9 个回答
  • Martin Hope
    EmmyS 我需要什么命令来解压缩/提取 .tar.gz 文件? 2011-02-09 14:50:41 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve