Linux - Crontab

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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值