crontab 定时任务
在指定的周期内执行指定的可执行脚本,时间间隔的单位可以是分钟、小时、日、月、周及以上的任意组合。
命令格式
crontab [-u user] file crontab [-u user] [ -e | -l | -r ]
# 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
列出crontab文件
$ crontab -l
编辑crontab文件
$ crontab -e
删除crontab文件
$ crontab -r
使用实例
1:每1分钟执行一次
* * * * * bashCommand
2:每小时的第5,10,15分钟执行
5,10,15 * * * * bashCommand
3:在上午8点到10点的第5和第15分钟执行
5,15 8-10 * * * bashCommand
4:每天的上午8点到11点隔5分钟执行
*/5 8-11 * * * myCommand
5:每周一上午8点到11点的第5和第15分钟执行
5,15 8-11 * * 1 bashCommand
6:每晚的18:30重启bashCommand
30 18 * * * bashCommand
7:每月1、10、22日的18:00执行bashCommand
00 18 1,10,22 * * bashCommand
8:每周六、周日的18 : 00执行bashCommand
00 18 * * 6,0 bashCommand
9:每天18 : 00至24 : 00之间每隔30分钟执行bashCommand
0,30 18-24 * * * bashCommand
10:每星期六的晚上11 : 00 pm执行bashCommand
0 23 * * 6 bashCommand
11:每一小时执行bashCommand
* */1 * * * bashCommand >& /dev/null
12:晚上24点到早上6点之间,每隔一小时执行bashCommand
0 24-7 * * * bashCommand > /dev/null 2 >& 1