Chinaunix

标题: crontab问题 [打印本页]

作者: gzhgyzhh    时间: 2012-12-06 15:00
标题: crontab问题
crontab 中,下面有什么区别

我想让我的脚本每小时执行一次命令

* */2 * * * 我这样设置后,每分钟执行一次命令?

0 */2 * * *
* */2 * * *

有知道的请告知下,谢谢
作者: chenyx    时间: 2012-12-06 16:12
* */2 * * *这个是每2小时执行一次,* */1 * * *才是1小时
作者: yizuwei520    时间: 2012-12-06 16:13
鸟哥私房菜里面有讲这个的,你看看。
作者: gzhgyzhh    时间: 2012-12-06 16:35
测试结果

0 */1 * * *  每小时执行一次
* */1 * * *  每分钟执行一次


作者: 枫之歌    时间: 2012-12-06 17:16
gzhgyzhh 发表于 2012-12-06 16:35
测试结果

0 */1 * * *  每小时执行一次
  1. SHELL=/bin/bash
  2. PATH=/sbin:/bin:/usr/sbin:/usr/bin
  3. MAILTO=root
  4. HOME=/

  5. # For details see man 4 crontabs

  6. # Example of job definition:
  7. # .---------------- minute (0 - 59)
  8. # |  .------------- hour (0 - 23)
  9. # |  |  .---------- day of month (1 - 31)
  10. # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
  11. # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
  12. # |  |  |  |  |
  13. # *  *  *  *  * user-name command to be executed
复制代码
我也试了一下,事实证明前面的时间一定要填上数值。如果都为*,即使你在月的位置*/1它也是每分钟执行一次。

Commands are executed by cron( when the
       minute, hour, and month of year fields match the current time, and at least one  of  the  two
       day  fields  (day  of month, or day of week) match the current time (see "Note" below).  Note
       that this means that non-existent times, such as "missing hours" during daylight savings con-
       version,  will  never match, causing jobs scheduled during the "missing times" not to be run.
       Similarly, times that occur more than once (again, during daylight savings  conversion)  will
       cause matching jobs to be run twice.




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2