2013-02-05 69 views
209

如何配置一个cron作业,每天晚上2:30运行?我知道如何让它在2点运行,但不是2点30分。每天凌晨2:30运行一个cron作业

+0

http://stackoverflow.com/questions/40231898/how-can-i-update-data-from-one-document-to-another-document-automatically-in-nod – 2016-10-25 06:10:51

回答

399
crontab -e 

地址:

30 2 * * * /your/command 
94
  1. 编辑:

    crontab -e 
    
  2. 添加此命令行:

    30 2 * * * /your/command 
    
    • crontab的格式:

      MIN HOUR DOM MON DOW CMD

    • 格式的含义和允许值:
    • MIN Minute field 0 to 59
    • HOUR Hour field 0 to 23
    • DOM Day of Month 1-31
    • MON Month field 1-12
    • DOW Day Of Week 0-6
    • CMD Command Any command to be executed.
  3. 重新启动的cron与最新数据:

    service crond restart 
    
+4

克朗不一定非要重新启动:http://stackoverflow.com/a/10193931/21027 –

+5

@Andre理论上你是对的,但实际上它有时并不奏效......你会通过#geotheory或其他许多人来检查评论......你在这里提到的同一页面上。谢谢http://stackoverflow.com/a/10193931/21027 –

+1

请记住,它符合服务器时区 –

6

一个简单的方法来写cron是使用在线的cron generator 它将生成专线为您服务。有一件事要注意,如果你想每天运行它(不只是平日),你需要突出显示所有的日子。

34

正如在其他的答案看出,使用语法是:

30 2 * * * /your/command 
#^^ 
# | hour 
# minute 

继crontab的标准格式:

+---------------- minute (0 - 59) 
| +------------- hour (0 - 23) 
| | +---------- day of month (1 - 31) 
| | | +------- month (1 - 12) 
| | | | +---- day of week (0 - 6) (Sunday=0 or 7) 
| | | | | 
* * * * * command to be executed 

它也使用crontab.guru检查crontab的表情非常有用。

使用crontab -e将表达式添加到crontab中。完成后,保存并退出(如果使用的是vi,则输入:x即可)。该好好想使用这个工具的是,如果你写了一个无效的命令,你很可能得到窗体上的消息提示:

$ crontab -e 
crontab: installing new crontab 
"/tmp/crontab.tNt1NL/crontab":7: bad minute 
errors in crontab file, can't install. 
Do you want to retry the same edit? (y/n) 

如果你还没有运行与crontab的进一步的问题,您可以检查Debugging crontabWhy is crontab not executing my PHP script?

-5

它必须是:

0 30 2 * * ?

第一个值描绘秒 第二个值描绘分钟 第3个值描绘小时 第四值描绘一个月 第5天值描述月份 这是我一直用来通过Quartz运行我的cron作业的内容

+3

这将是第2天,在时间30:0(不可能) –