说明:Crontab是Linux系统中在固定时间执行某一个程序的工具,类似于Windows系统中的任务计划程序

下面通过详细实例来说明在Linux系统中如何使用Crontab

操作系统:CentOS

一、安装crontab

yum install vixie-cron  #安装

chkconfig crond on  #设为开机启动,先要安装chkconfig(yum install chkconfig)

service crond start  #启动

service crond stop  #停止

/etc/rc.d/init.d/crond restart  #重启

/etc/rc.d/init.d/crond reload  #不中断服务,重新载入配置

二、设置任务计划

/home/www.osyunwei.com/osyunwei.sh    #要自动执行的脚本程序路径

chmod +x /home/www.osyunwei.com/osyunwei.sh   #对脚本文件添加执行权限,否则不能执行

vi /etc/crontab  #编辑配置文件,在最后一行添加内容

30 1 * * * root /home/www.osyunwei.com/osyunwei.sh #表示每天凌晨1点30执行备份

:wq! #保存退出

系统运维 www.osyunwei.com 温馨提醒:qihang01原创内容版权所有,转载请注明出处及原文链接

/etc/rc.d/init.d/crond restart  #重启

备注:

系统运维 www.osyunwei.com 温馨提醒:qihang01原创内容版权所有,转载请注明出处及原文链接

crontab文件的格式:

minute    hour    day    month    weekday    username     command

minute:分,值为0-59

hour:小时,值为1-23

day:天,值为1-31

month:月,值为1-12

weekday:星期,值为0-6(0代表星期天,1代表星期一,以此类推)

username:要执行程序的用户,一般设置为root

command:要执行的程序路径(设置为绝对路径)例如:/home/www.osyunwei.com/osyunwei.sh

附:crontab规则详细实例

1、每天6:00执行

0 6 * * * root /home/www.osyunwei.com/osyunwei.sh

2、每周六凌晨4:00执行

0 4 * * 6 root /home/www.osyunwei.com/osyunwei.sh

3、每周六凌晨4:05执行

5 4 * * 6 root /home/www.osyunwei.com/osyunwei.sh

4、每周六凌晨4:15执行

15 4 * * 6 root /home/www.osyunwei.com/osyunwei.sh

5、每周六凌晨4:25执行

25 4 * * 6 root /home/www.osyunwei.com/osyunwei.sh

6、每周六凌晨4:35执行

35 4 * * 6 root /home/www.osyunwei.com/osyunwei.sh

7、每周六凌晨5:00执行

5 * * 6 root /home/www.osyunwei.com/osyunwei.sh

8、每天8:40执行

40 8 * * * root /home/www.osyunwei.com/osyunwei.sh

9、每天8:30执行

30 8 * * * root /home/www.osyunwei.com/osyunwei.sh

10、每周一到周五的11:41开始,每隔10分钟执行一次

41,51 11 * * 1-5   root /home/www.osyunwei.com/osyunwei.sh

1-59/10 12-23 * * 1-5   root /home/www.osyunwei.com/osyunwei.sh

11、在每天的10:31开始,每隔2小时重复一次

31 10-23/2 * * * root   /home/www.osyunwei.com/osyunwei.sh

12、每天15:00执行

0 15 * * *  root /home/www.osyunwei.com/osyunwei.sh

13、每天的10:30开始,每隔2小时重复一次

30 10-23/2 * * * root  /home/www.osyunwei.com/osyunwei.sh

14、每天15:30执行

30 15 * * *  root /home/www.osyunwei.com/osyunwei.sh

15、每天17:50执行

50 17 * * *  root /home/www.osyunwei.com/osyunwei.sh

16、每天8:00执行

0 8 * * *  root  /home/www.osyunwei.com/osyunwei.sh

17、每天18:00执行

0 18 * * *  root  /home/www.osyunwei.com/osyunwei.sh

18、每天8:30执行

系统运维 www.osyunwei.com 温馨提醒:qihang01原创内容版权所有,转载请注明出处及原文链接

30 8 * * *  root  /home/www.osyunwei.com/osyunwei.sh

19、每天20:30

30 20 * * *  root /home/www.osyunwei.com/osyunwei.sh

20、每周一到周五2:00

0 2 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

21、每周一到周五9:30

30 9 * * 1-5 root /home/www.osyunwei.com/osyunwei.sh

22、每周一到周五8:00,每周一到周五9:00

0 8,9 * * 1-5  root /home/www.osyunwei.com/osyunwei.sh

23、每天23:59

59 23 * * *  root  /home/www.osyunwei.com/osyunwei.sh

24、每周六23:59

59 23 * * 6  root    /home/www.osyunwei.com/osyunwei.sh

25、每天0:30

30 0 * * *  root  /home/www.osyunwei.com/osyunwei.sh

26、每周一到周五9:25到11:35之间、13:00到15:00之间,每隔10分钟运行一次

25,35,45,55  9 * * 1-5  root   /home/www.osyunwei.com/osyunwei.sh

5-59/10  10 * * 1-5  root   /home/www.osyunwei.com/osyunwei.sh

5,15,25,35  11 * * 1-5  root   /home/www.osyunwei.com/osyunwei.sh

*/10  13-15 * * 1-5  root   /home/www.osyunwei.com/osyunwei.sh

27、每周一到周五8:30、8:50、9:30、10:00、10:30、11:00、11:30、13:30、14:00、14:30、5:00分别执行一次

30,50 8 * * 1-5  root  /home/www.osyunwei.com/osyunwei.sh

30 9 * * 1-5  root  /home/www.osyunwei.com/osyunwei.sh

*/30 10-11 * * 1-5  root  /home/www.osyunwei.com/osyunwei.sh

30 13 * * 1-5  root  /home/www.osyunwei.com/osyunwei.sh

0,30 14-15 * * 1-5  root  /home/www.osyunwei.com/osyunwei.sh

28、每天23:50执行

50 23 * * *  root  /home/www.osyunwei.com/osyunwei.sh

29、每天10:00、16:00执行

0 10,16 * * *  root /home/www.osyunwei.com/osyunwei.sh

30、每天5:30执行

30 5 * * *  root  /home/www.osyunwei.com/osyunwei.sh

31、每周一到周五9:30执行

30 9 * * 1-5  root  /home/www.osyunwei.com/osyunwei.sh

32、每周一到周五13:00执行

0 13 * * 1-5  root  /home/www.osyunwei.com/osyunwei.sh

33、每天7:51执行

51 7 * * *  root /home/www.osyunwei.com/osyunwei.sh

34、每天7:53、12:40分别执行一次

53 7 * * *  root /home/www.osyunwei.com/osyunwei.sh

40 12 * * *  root /home/www.osyunwei.com/osyunwei.sh

35、每天7:55执行

55 7 * * *  root  /home/www.osyunwei.com/osyunwei.sh

36、每天8:10、16:00、20:00分别执行一次

10 8 * * *  root  /home/www.osyunwei.com/osyunwei.sh

0 16 * * *  root  /home/www.osyunwei.com/osyunwei.sh

0 20 * * *  root  /home/www.osyunwei.com/osyunwei.sh

37、每天7:57、8:00分别执行一次

57 7 * * *  root  /home/www.osyunwei.com/osyunwei.sh

0 8 * * *  root  /home/www.osyunwei.com/osyunwei.sh

至此,Linux计划任务Crontab实例详解教程完成

转载自系统运维 » Linux计划任务Crontab实例详解教程

linux cron计划任务的更多相关文章

  1. linux cron计划任务、chkconfig 命令、systemd命令、unit 相关、target 相关

    1.设置说明位置 : cat /etc/crontab # Example of job definition:# .---------------- minute (0 - 59)# | .---- ...

  2. linux cron计划任务防止多个任务同时运行

    使用linux flock 文件锁实现任务锁定,解决冲突格式:flock [-sxun][-w #] fd#flock [-sxon][-w #] file [-c] command选项-s, --s ...

  3. linux任务计划cron

    linux任务计划cron 1.crontab命令任务计划配置文件 [root@bogon ~]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/ ...

  4. linux任务计划cron、chkconfig工具、systemd管理服务、unit和target介绍

    第8周第1次课(5月14日) 课程内容: 10.23 linux任务计划cron10.24 chkconfig工具10.25 systemd管理服务10.26 unit介绍10.27 target介绍 ...

  5. Linux centos7 linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍、 target介绍

    一.linux任务计划cron crontab -u  -e -l -r 格式;分 时 日 月 周 user command 文件/var/spool/corn/username 分范围0-59,时范 ...

  6. Linux任务计划

    Linux任务计划: 一次性任务执行(at.batch): at:定时任务,指定一个时间执行一个任务,只能执行一次. at使用方式: 交互式:让用户在at>提示符输入多个要执行的命令: 批处理: ...

  7. 配置Linux任务计划

    Linux有三种计划任务: at:指定一个时间执行一个任务 (适用一个或多个任务,执行一次后就不用) cron:根据一个时间表自动执行任务 (使用一个或多个任务,周期性执行) 系统级别的计划任务及其扩 ...

  8. linux crontab 计划任务 atd和windows下的计划任务

    crontab 命令 如果发现您的系统里没有这个命令,请安装下面两个软件包. vixie-cron crontabs crontab 是用来让使用者在固定时间或固定间隔执行程序之用,换句话说,也就是类 ...

  9. linux周期性计划任务 进程管理

    周期性计划任务crontab命令系统服务:/etc/init.d/crond(crond必须启动才会生效)用户计划:/var/spool/cron/用户名默认的计划任务全局配置:/etc/cronta ...

随机推荐

  1. 实际项目中的一个angularjs 应用

    实际需求:通过下拉框,选择自己需要的类型,创建元素(要求必须是输入点击保存了才能出现对应的类型块) html代码: <div class="list-panel-data"& ...

  2. 制作简单的2D物理引擎(零)

    最近发现了Github上的开源物理引擎项目Matter.js,对它很感兴趣,发现源码并不算长,算上注释大约1万行左右,值得剖析一番.Matter.js实现一个最小化的2D物理引擎,性能不错,故打算用C ...

  3. Mongodb 副本集分片(二)---mongodb副本集部署脚本详解

    分享下,最近做的一主一从一仲裁的示例,如有需要,大家可以扩展成一主两从一仲裁. 大家可以看到  我的集群名字沿用了默认的neunnm,如果是其他的话   大家注意修改. 需要辅助文件hosts.con ...

  4. SSM框架学习之高并发秒杀业务--笔记5-- 并发优化

    前几节终于实现了这个高并发秒杀业务,现在问题是如何优化这个业务使其能扛住一定程度的并发量. 一. 优化分析 对于整个业务来说,首先是分析哪些地方会出现高并发,以及哪些地方会影响到了业务的性能.可能会出 ...

  5. silk mpu

    #include "mpu.h" #include "mbuf.h" #include "media_buffer.h" #include ...

  6. Sql Server xml 类型字段的增删改查

    1.定义表结构 在MSSM中新建数据库表CommunicateItem,定义其中一个字段ItemContentXml 为xml类型 2.编辑表数据,新增一行,发现xml类型不能通过设计器录入数据. 需 ...

  7. node.js+socket.io安装

    最近做安卓遇到一个网络包的bug,服务端使用node做的,通讯用socket.io,但是服务端没法调试,没办法,还是自己搭建一个服务器端吧,索性买了阿里云的ecs测试,之前也配置过node+socke ...

  8. Practical Malware Analysis里有关inetsim\APATEDNS

    以前从未接触过linux,碰到了许多问题,按步骤: 1\安装VMWARE,安装ubuntu16.04 问题1:之前装的是VM10,装完后没有安装VMTOOLS,我点安装 VMTOOLS,它弹出“简易安 ...

  9. 数据表格datagrid内容整理

    <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...

  10. hadoop输入分片计算(Map Task个数的确定)

    作业从JobClient端的submitJobInternal()方法提交作业的同时,调用InputFormat接口的getSplits()方法来创建split.默认是使用InputFormat的子类 ...