Cron的深入研究

[| 不指定 2008/08/07 15:19]
| |
1:究竟什么时间被执行,是与还是或?下面是一个特殊的例子,群里有朋友问,我就测试了一下。

[root@ha01 conf]# crontab -l
1 1 1 1 1 /bin/date > /tmp/date.log


复习一下这五个字段:minute(0-59)  hour(0-23)  day of month(1-31) month(1-12) day of week(0-7)

很多朋友将上面的定义解读为:在1月1号的凌晨1:01分执行,且那天为星期一。
按照这个说法,恐怕几年也不会运行了。

但是实际上是:1月的每个星期一和1号这些天,在凌晨的1:01分执行。
也就是说:第三个字段和第五个字段是或的关系。而不是与的关系。满足任何一个都会运行了。

再看一下man帮助里面的说法:

[root@ha01 conf]# man 5 crontab
................

       Note:  The  day of a command’s execution can be specified by two fields — day of month, and day of week.  If both fields are restricted
       (ie, aren’t *), 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.

................

看到那个例子了吗?plus翻译成"加上"


2:关于环境变量的问题。
cron里面所继承的环境变量非常有限。尽量用绝对路径。会减少你很多麻烦。自己多试验一下吧。
多半出错,是因为这个原因的。

本文链接:http://www.52zhe.cn/read.php/194.htm
本文作者:kook(若就博客内所涉及的技术问题交流,请用下面的MSN或Gmail联系我)
联系方式:(MSN:kook#live.com) (Google talk:kookliu)
没有版权:GNU,转载时请注明“转载人”欠本人一顿饭,来日见面之时兑现!谢谢合作!
by kook | 分类: Linux | 评论(0) | 引用(0) | 阅读(970)
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]