Advertisement

CRON定时任务

阅读量:

CRON定时任务

[root@localhost cron.d]# cat /etc/crontab

复制代码
 SHELL=/bin/bash

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

其中一些特殊符号含义:

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

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

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

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

/etc/cron.d 和/etc/crontab 的区别:

简单来说,/etc/cron.d 下的定时任务是需要选用户的,eg:*/1 * * * * root /usr/local/sbin/scripts/test.sh

而/etc/crontab 下的定时任务是,eg:*/1 * * * * /usr/local/sbin/scripts/test.sh

查看编辑命令:

1.crontab -l ---》列出定时任务

2.crontab -e ---》编辑定时任务

3.crontab -r ---》删除定时任务

全部评论 (0)

还没有任何评论哟~