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

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

一、安装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! #保存退出

******************************************************************************************************

crontab [-u user] file

crontab [-u user] [ -e | -l | -r ]

-u user:用来设定某个用户的crontab服务,例如,“-u ixdba”表示设定ixdba用户的crontab服务,此参数一般有root用户来运行。

file:file是命令文件的名字,表示将file做为crontab的任务列表文件并载入crontab。如果在命令行中没有指定这个文件,crontab命令将接受标准输入(键盘)上键入的命令,并将它们载入crontab。

-e:编辑某个用户的crontab文件内容。如果不指定用户,则表示编辑当前用户的crontab文件。

-l:显示某个用户的crontab文件内容,如果不指定用户,则表示显示当前用户的crontab文件内容。

-r:从/var/spool/cron目录中删除某个用户的crontab文件,如果不指定用户,则默认删除当前用户的crontab文件。

-i:在删除用户的crontab文件时给确认提示。

*****************************************************************************************************

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

例子:

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介绍相关推荐

  1. linux计划任务案例,Linux计划任务Crontab学习笔记(5):常见错误使用案例

    ① 环境变量 复制代码代码如下: cd ~ pwd 就会到你登陆的那个用户的根目录下 复制代码代码如下: ls -a 能够查看到 .bash_profile 这个文件 复制代码代码如下: vim .b ...

  2. 计划任务文件 linux,Linux计划任务Crontab学习笔记(3):配置文件

    [全局(系统)配置文件] 复制代码代码如下: /etc/crontab Linux 主要的配置文件都在 etc 目录下. 复制代码代码如下: cd /etc ls cron* 复制代码代码如下: vi ...

  3. Linux 计划任务 — crontab

    cron 简介 cron 是 UNIX, SOLARIS,LINUX 下的一个十分有用的工具.通过 cron 脚本能使计划任务定期地在系统后台自动运行. cron 命令 crontab -e – 编辑 ...

  4. Linux计划任务(at/crontab)

    linux计划任务(crontab) 一.仅执行一次的定时任务-atd 1. at是个可以处理仅执行一次就结束的定时任务的命令,需要先启动atd服务 2. 启动atd服务 查看atd服务的状态(大部分 ...

  5. linux的周期计划任务叫atd,linux计划任务

    一.单一计划任务 安装at: # yum -y install at 启动: # /etc/init.d/atd start 查看是否运行: # ps aux | grep atd 创建计划 # at ...

  6. linux 创建crontab文件位置,[基础教程]linux系统的crontab计划任务添加和删除

    在linux系统中,有时候为了节省人力,所以将一些脚本进行定时执行,通过crontab计划任务进行启动和停止,这样能方便大部分时间来做其他事情,下面主要介绍一下如何启动和删除crontab计划任务 添 ...

  7. Linux计划任务(at,crontab)

    在LINUX中,我们通过crontab和at这两个东西来实现 at:它是一个可以处理仅执行一次就结束的指令 crontab:它是会把你指定的工作或任务,比如:脚本等,按照你设定的周期一直循环执行下去 ...

  8. AIX 与Linux 中crontab 介绍

    AIX 与Linux 中crontab 用法相似,先介绍Linux 中的Crontab 用法,再后介绍AIX 与Linux 的不同之处.   一.Crontab 介绍 crontab命令的功能是在一定 ...

  9. Linux中的计划任务—Crontab调度一次性执行的任务at/batch

    概述 前不久我们梳理了Linux中的计划任务-Crontab调度重复执行的任务,但是有些场景我们只是需要执行一次,执行完就结束任务该怎么办呢? 这里我们要用到linux提供的at/batch命令. 本 ...

最新文章

  1. vue2.0 + vux (五)api接口封装 及 首页 轮播图制作
  2. 哥伦比亚大学的材料更新提交窗口!干货!
  3. 通过RocketMQ的java客户端api进行测试
  4. JQ之路——layer第三方弹窗
  5. MyBatis复习(一):开眼看世界
  6. boot入门思想 spring_(第一讲)Spring Initializr-快速入门Spring Boot的最好选择
  7. [导入]C#面向对象设计模式纵横谈(18):(行为型模式) Iterator 迭代器模式.zip(8.04 MB)...
  8. 60-140-044-使用-DataSink-使用OutputTag进行Side Output(侧输出)
  9. python 字符串不相等_python实现找出来一个字符串中最长不重复子串
  10. 亿图图示edraw max mac版
  11. 网吧计费管理系统(武汉理工大学大一下实验(C语言版源码))
  12. Apollo学习笔记(8)车辆动力学模型
  13. 虚拟机安装黑苹果【虚拟机安装,黑苹果安装,黑苹果无法全屏问题】(这应该全网最全的资源了吧~)
  14. 多态 继承 封装 打印输出长方形 正方形 圆形的周长和面积
  15. uniapp-小程序与H5压缩图片上传
  16. 大写金额转换(报销大写金额转换)
  17. 1709: 简小胡的背包
  18. 四级词汇4000快速记忆
  19. Flink 入门教程
  20. 成功解决: Windows10没有蓝牙问题

热门文章

  1. go 用 mysql web开发环境_简单讲解Go程序中使用MySQL的方法
  2. 判断元素是否在ndarray_专业文章 | 如何判断是否构成有“一定影响”的包装装潢...
  3. matlab两个图共用一个x轴_SCI论文写作MATLAB出图(2)
  4. python怎么对齐文件_说说在 python 中,如何对齐文本
  5. 抽象工厂模式_抽象工厂模式
  6. 服务器的共享文件夹怎么隐藏,Server200服务器隐藏共享文件夹 隐藏共享文件的方法...
  7. 暴力子字符串查找算法
  8. ConstraintLayout如何优化布局性能
  9. IOS开发基础知识--碎片8
  10. OSPF的LSA类型~