Dec 11

[原]Linux下crontab中的宏 不指定

linuxing , 10:36 , 基础知识 » 系统命令 , 评论(0) , 引用(0) , 阅读(17988) , Via 本站原创 | |
   很久以前,写过一篇[原]linux下实行计划任务,其中比较详细的介绍了如何使用Linux下的crontab对系统进行例行性管理的工作。这里想对其中的内容进行一些补充。增加crontab中可用宏的说明。

一、时间栏的定义
使用crontab -e可编译计划任务,格式为:
引用
* *  *  *  * 命令
前面的五个*号,表示分、时、日、月、周

cron服务的最少间隔周期为1分钟,即每1分钟cron服务会检查一次系统中保存的计划任务信息。
而时间栏的定义为:
引用
field       allowed values
-----       --------------
minute       0-59
hour       0-23
day of month   1-31
month       1-12 (或者月份的简写)
day of week    0-7 (0 or 7,7是周日,或者使用简写)

若表示范围,可使用:
引用
* 代表全部,任意匹配;
- 表示范围,例如:在分钟栏,0-10,就是0到10分;
/ 表示间隔,例如:在分钟栏,*/5,就是每5分钟,小时栏,0-23/2,就是每2小时;

二、宏
除使用上述写法外,还可以使用“nicknames”的定义:
引用
@reboot    :    Run once, at startup.
@yearly    :    Run once a year, ie.  "0 0 1 1 *".
@annually  :    Run once a year, ie.  "0 0 1 1 *".
@monthly    :    Run once a month, ie. "0 0 1 * *".
@weekly    :    Run once a week, ie.  "0 0 * * 0".
@daily    :    Run once a day, ie.   "0 0 * * *".
@hourly    :    Run once an hour, ie. "0 * * * *".

三、举例
每15分钟执行一次:
引用
*/15 * * * * /opt/test.sh
0,15,30,45 * * * * /opt/test.sh

每日的0时0分执行一次:
引用
@daily /opt/test.sh
0 0 * * *  /opt/test.sh

启动的时候自动执行(相当于放到rc.local中):
引用
@reboot /opt/test.sh

更详细的信息,请看man 5 crontab。
Tags:
发表评论
表情
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
emotemotemotemotemot
打开HTML
打开UBB
打开表情
隐藏
记住我
昵称   密码   游客无需密码
网址   电邮   [注册]