码迷,mamicode.com
首页 > 系统相关 > 详细

linux之crontab

时间:2019-08-17 00:51:14      阅读:91      评论:0      收藏:0      [点我收藏+]

标签:name   detail   div   class   sbin   pre   date   时间同步   字段   

查看任务

crontal -l

编辑任务

1 crontab -e

编辑crontab文件

1 vim /etc/crontab
 1 SHELL=/bin/bash
 2 PATH=/sbin:/bin:/usr/sbin:/usr/bin
 3 MAILTO=root
 4 
 5 # For details see man 4 crontabs
 6 
 7 # Example of job definition:
 8 # .---------------- minute (0 - 59)
 9 # |  .------------- hour (0 - 23)
10 # |  |  .---------- day of month (1 - 31)
11 # |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
12 # |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
13 # |  |  |  |  |
14 # *  *  *  *  * user-name  command to be executed

语法

crontab任务配置基本格式:
*  *  *  *  *  command
分钟(0-59) 小时(0-23) 日期(1-31) 月份(1-12) 星期(0-6,0代表星期天)  命令

第1列表示分钟1~59 每分钟用*或者 */1表示
第2列表示小时1~23(0表示0点)
第3列表示日期1~31
第4列表示月份1~12
第5列标识号星期0~6(0表示星期天)
第6列要运行的命令

星号(*):代表所有可能的值,例如month字段如果是星号,则表示在满足其它字段的制约条件后每月都执行该命令操作。
08 * * *  每天8.30去上班  

逗号(,):可以用逗号隔开的值指定一个列表范围,例如,“1,2,5,7,8,9”

中杠(-):可以用整数之间的中杠表示一个整数范围,例如“2-6”表示“2,3,4,5,6”

正斜线(/):可以用正斜线指定时间的间隔频率,例如“0-23/2”表示每两小时执行一次。同时正斜线可以和星号一起使用,例如*/10,如果用在minute字段,表示每十分钟执行一次。
*/3 * * * * /usr/sbin/ntpdate ntp1.aliyun.com  每隔三分钟执行下时间同步

 

linux之crontab

标签:name   detail   div   class   sbin   pre   date   时间同步   字段   

原文地址:https://www.cnblogs.com/Alexephor/p/11363042.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!