ref   https://blog.csdn.net/xiangxianghehe/article/details/78149094

一.安装 crontabs服务并设置开机自启:

yum install crontabs
systemctl enable crond
systemctl start crond
systemctl stop crond
 

二.设置用户自定义定时任务:

vi /etc/crontab

可以看到:

# 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

即:

分钟(0-59) 小时(0-23) 日(1-31) 月(11-12) 星期(0-6,0表示周日) 用户名 要执行的命令1

每隔30分钟root执行一次updatedb命令:

*/30 * * * * root updatedb

每天早上5点定时重启系统:

0 5 * * * root reboot1

每隔三秒执行一次/home/somedir目录下的scripts.sh脚本:

## For excuting scripts.sh every 3 seconds##on 2014-10-15
*/1 * * * * /home/somedir/scripts.sh
*/1 * * * * sleep 3 && /home/somedir/scripts.sh
*/1 * * * * sleep 6 && /home/somedir/scripts.sh
*/1 * * * * sleep 9 && /home/somedir/scripts.sh
*/1 * * * * sleep 12 && /home/somedir/scripts.sh
*/1 * * * * sleep 15 && /home/somedir/scripts.sh
*/1 * * * * sleep 18 && /home/somedir/scripts.sh
*/1 * * * * sleep 21 && /home/somedir/scripts.sh
*/1 * * * * sleep 24 && /home/somedir/scripts.sh
*/1 * * * * sleep 27 && /home/somedir/scripts.sh
*/1 * * * * sleep 30 && /home/somedir/scripts.sh
*/1 * * * * sleep 33 && /home/somedir/scripts.sh
*/1 * * * * sleep 36 && /home/somedir/scripts.sh
*/1 * * * * sleep 39 && /home/somedir/scripts.sh
*/1 * * * * sleep 42 && /home/somedir/scripts.sh
*/1 * * * * sleep 45 && /home/somedir/scripts.sh
*/1 * * * * sleep 48 && /home/somedir/scripts.sh
*/1 * * * * sleep 51 && /home/somedir/scripts.sh
*/1 * * * * sleep 54 && /home/somedir/scripts.sh
*/1 * * * * sleep 57 && /home/somedir/scripts.sh

三.保存生效:

#加载任务,使之生效
crontab /etc/crontab #查看任务
crontab -l # stop
 systemctl stop crond
 

CentOS7设置定时任务 每隔30分钟执行一次命令的更多相关文章

  1. 用ab每隔30分钟并发一次休息10分钟

    linux脚本监控程序运行情况(重启程序)主要有两种情况:一种是一个可执行文件:如shell脚本文件:另一种是使用python打开的多个程序.第一种:它的进程名字由路径名字和程序名字组成,比如:我有个 ...

  2. linux定时任务每隔5分钟向文本追加一行

    编写shell脚本 test.sh内容如下,上传到linux的root目录 更改文件权限 chmod  777   test.sh 编辑定时任务 crontab  -e */5    *  *  *  ...

  3. crontab 定时任务 每过多少分钟执行

    被下面的问题纠结了一会 记录一下以备提醒 每过5分钟执行 */ * * * * curl localhost/system/dns/dnns.php?ac=ToDNS 每小时的第五分钟执行 0 * * ...

  4. centos7设置定时任务

    第一种方式修改/etc/crontab文件,这种方式是系统的周期任务,只能root用户才可以执行 SHELL=/bin/bashPATH=/sbin:/bin:/usr/sbin:/usr/binMA ...

  5. Shell编程(八)每隔N分钟执行某脚本

    sudo crontab -e

  6. 【Jenkins】三、设置定时任务

    1.点击工程(Test1), 选择左侧的配置 2.选择"构建触发器"下面的"定时构建" 3.填写定时规则(这里设置每隔30分钟执行一次) 4.定时规则语法字段 ...

  7. 【win7 + win server 2008】设置定时任务,设置.bat 文件去执行php脚本 == 用来配合爬虫程序简直不要太爽

    Windows Server 2008中使用计划任务定时执行BAT bat进行PHP脚本的执行 一.首先进行任务管理器设置  每隔1分钟执行.BAT 文件配置 首先Windows Server 200 ...

  8. 如何设置一个严格30分钟过期的Session(转载)

    本文地址: http://www.laruence.com/2012/01/10/2469.html 今天在我的微博(Laruence)上发出一个问题: 我在面试的时候, 经常会问一个问题: &quo ...

  9. 如何设置session过期时间为30分钟

    今天在我的微博(Laruence)上发出一个问题: 我在面试的时候, 经常会问一个问题: “如何设置一个30分钟过期的Session?”, 大家不要觉得看似简单, 这里面包含的知识挺多, 特别适合考察 ...

随机推荐

  1. [3]传奇3服务器源码分析一 DBServer

    留存 服务端下载地址: 点击这里

  2. GDTR与LDTR

    ----段寄存器 一.访问GDT 当TI=0时表示段描述符在GDT中,如上图所示: 段描述符(64位) ①先从GDTR寄存器(48位,其中前32位base+16位长度)中获得GDT基址. ②然后再GD ...

  3. 《大话设计模式》c++实现 代理模式

    代理模式 在代理模式(Proxy Pattern)中,一个类代表另一个类的功能.这种类型的设计模式属于结构型模式. 在代理模式中,我们创建具有现有对象的对象,以便向外界提供功能接口. 介绍 意图:为其 ...

  4. MOG插件(葡萄牙语,略作翻译)

    这次记录下MOG大神的插件,自从我发现了这个插件,似乎开启了一个新世界诶~~~ 网址 https://atelierrgss.wordpress.com 1. MOG_YuruYuri.js CARA ...

  5. Yii restful api跨域

    问题:NO 'Access-Control_Allow-Origin' header is present on the requested resource. 解决方案 <?php names ...

  6. 深度解读 AlphaGo 算法原理

    http://blog.csdn.net/songrotek/article/details/51065143 http://blog.csdn.net/dinosoft/article/detail ...

  7. 20155228 实验二 Java面向对象程序设计

    20155228 实验二 Java面向对象程序设计 实验内容 1. 初步掌握单元测试和TDD 2. 理解并掌握面向对象三要素:封装.继承.多态 3. 初步掌握UML建模 4. 熟悉S.O.L.I.D原 ...

  8. ReactiveCocoa(III)

    flatMap(FlattenStrategy.latest) observe(on: UIScheduler()).startWithResult 切换线程: observeOn(UISchedul ...

  9. tensorflow--variable_scope

    1.with tf.variable_scope(name , reuse = reuse) (1)创建variable scope with tf.variable_scope("foo& ...

  10. MyBatis学习(一)简单入门程序

    MyBatis入门学习 MyBatis 本是apache的一个开源项目iBatis, 2010年这个项目由apache software foundation 迁移到了google code,并且改名 ...