1、使用sleep

在crontab中加入

* * * * * sleep 10; /bin/date >>/tmp/date.txt
* * * * * sleep 20; /bin/date >>/tmp/date.txt
* * * * * sleep 30; /bin/date >>/tmp/date.txt
* * * * * sleep 40; /bin/date >>/tmp/date.txt
* * * * * sleep 50; /bin/date >>/tmp/date.txt

跟踪日志,可以看到是每10秒钟执行一次。

tail -f date.txt
Thu Mar 9 16:00:12 CST 2017
Thu Mar 9 16:00:22 CST 2017
Thu Mar 9 16:00:32 CST 2017
Thu Mar 9 16:00:42 CST 2017
Thu Mar 9 16:00:52 CST 2017
Thu Mar 9 16:01:11 CST 2017
Thu Mar 9 16:01:21 CST 2017
Thu Mar 9 16:01:31 CST 2017

每秒钟执行,

* * * * * sleep 1 ; /bin/date >>/tmp/date.txt
* * * * * sleep 2 ; /bin/date >>/tmp/date.txt
* * * * * sleep 3 ; /bin/date >>/tmp/date.txt
* * * * * sleep 4 ; /bin/date >>/tmp/date.txt
* * * * * sleep 5 ; /bin/date >>/tmp/date.txt
* * * * * sleep 6 ; /bin/date >>/tmp/date.txt
* * * * * sleep 7 ; /bin/date >>/tmp/date.txt
* * * * * sleep 8 ; /bin/date >>/tmp/date.txt
* * * * * sleep 9 ; /bin/date >>/tmp/date.txt
* * * * * sleep 10 ; /bin/date >>/tmp/date.txt
* * * * * sleep 11 ; /bin/date >>/tmp/date.txt
* * * * * sleep 12 ; /bin/date >>/tmp/date.txt
* * * * * sleep 13 ; /bin/date >>/tmp/date.txt
* * * * * sleep 14 ; /bin/date >>/tmp/date.txt
* * * * * sleep 15 ; /bin/date >>/tmp/date.txt
* * * * * sleep 16 ; /bin/date >>/tmp/date.txt
* * * * * sleep 17 ; /bin/date >>/tmp/date.txt
* * * * * sleep 18 ; /bin/date >>/tmp/date.txt
* * * * * sleep 19 ; /bin/date >>/tmp/date.txt
* * * * * sleep 20 ; /bin/date >>/tmp/date.txt
* * * * * sleep 21 ; /bin/date >>/tmp/date.txt
* * * * * sleep 22 ; /bin/date >>/tmp/date.txt
* * * * * sleep 23 ; /bin/date >>/tmp/date.txt
* * * * * sleep 24 ; /bin/date >>/tmp/date.txt
* * * * * sleep 25 ; /bin/date >>/tmp/date.txt
* * * * * sleep 26 ; /bin/date >>/tmp/date.txt
* * * * * sleep 27 ; /bin/date >>/tmp/date.txt
* * * * * sleep 28 ; /bin/date >>/tmp/date.txt
* * * * * sleep 29 ; /bin/date >>/tmp/date.txt
* * * * * sleep 30 ; /bin/date >>/tmp/date.txt
* * * * * sleep 31 ; /bin/date >>/tmp/date.txt
* * * * * sleep 32 ; /bin/date >>/tmp/date.txt
* * * * * sleep 33 ; /bin/date >>/tmp/date.txt
* * * * * sleep 34 ; /bin/date >>/tmp/date.txt
* * * * * sleep 35 ; /bin/date >>/tmp/date.txt
* * * * * sleep 36 ; /bin/date >>/tmp/date.txt
* * * * * sleep 37 ; /bin/date >>/tmp/date.txt
* * * * * sleep 38 ; /bin/date >>/tmp/date.txt
* * * * * sleep 39 ; /bin/date >>/tmp/date.txt
* * * * * sleep 40 ; /bin/date >>/tmp/date.txt
* * * * * sleep 41 ; /bin/date >>/tmp/date.txt
* * * * * sleep 42 ; /bin/date >>/tmp/date.txt
* * * * * sleep 43 ; /bin/date >>/tmp/date.txt
* * * * * sleep 44 ; /bin/date >>/tmp/date.txt
* * * * * sleep 45 ; /bin/date >>/tmp/date.txt
* * * * * sleep 46 ; /bin/date >>/tmp/date.txt
* * * * * sleep 47 ; /bin/date >>/tmp/date.txt
* * * * * sleep 48 ; /bin/date >>/tmp/date.txt
* * * * * sleep 49 ; /bin/date >>/tmp/date.txt
* * * * * sleep 50 ; /bin/date >>/tmp/date.txt
* * * * * sleep 51 ; /bin/date >>/tmp/date.txt
* * * * * sleep 52 ; /bin/date >>/tmp/date.txt
* * * * * sleep 53 ; /bin/date >>/tmp/date.txt
* * * * * sleep 54 ; /bin/date >>/tmp/date.txt
* * * * * sleep 55 ; /bin/date >>/tmp/date.txt
* * * * * sleep 56 ; /bin/date >>/tmp/date.txt
* * * * * sleep 57 ; /bin/date >>/tmp/date.txt
* * * * * sleep 58 ; /bin/date >>/tmp/date.txt
* * * * * sleep 59 ; /bin/date >>/tmp/date.txt

2、使用脚本运行

#!/bin/bash

step=2 #间隔的秒数,不能大于60

for (( i=0; i<60; i=(i+step) )); do
date
sleep $step
done

exit 0

添加到crontab中

crontab -l
* * * * * sh /root/crontab.sh >> /tmp/crontab.log

查看日志

tail -f tail -f /tmp/crontab.log

crontab每10秒钟执行一次的更多相关文章

  1. Linux定时任务crontab每三秒执行一次shell

    第一种方法:当然首先想到的是写一个触发的脚本,在触发脚本中使用死循环来解决此问题,如下: cat kick.sh #!/bin/bash while : ;do /home/somedir/scrip ...

  2. linux crontab & 每隔10秒执行一次

    linux下定时执行任务的方法  在LINUX中你应该先输入crontab -e,然后就会有个vi编辑界面,再输入0 3 * * 1 /clearigame2内容到里面 :wq 保存退出. 在LINU ...

  3. Crontab中shell每分钟执行一次HDFS文件上传不执行的解决方案

    一.Crontab -e 加入输出Log */1 * * * * /qiwen_list/upload_to_hdfs.sh > /qiwen_list/mapred.log 2>& ...

  4. cron和crontab命令详解 crontab 每分钟、每小时、每天、每周、每月、每年定时执行 crontab每5分钟执行一次

    cron机制        cron可以让系统在指定的时间,去执行某个指定的工作,我们可以使用crontab指令来管理cron机制 crontab参数        -u:这个参数可以让我们去编辑其他 ...

  5. linux定时任务crontab 实现如何每秒执行一次!

    linux crontab 命令,最小的执行时间是一分钟.如需要在小于一分钟内重复执行,可以有两个方法实现. Cron 各项的描述 以下是 crontab 文件的格式: {minute} {hour} ...

  6. ubuntu crontab 在时间段内随机执行一次

    crontab 在linux下做定时任务的命令, 1. 基本格式 * * * * * cmd 第一个表示:分钟 1-59, 每分钟用 */1 第二个表示:小时 023 第三个表示:日期1-31 第四个 ...

  7. pthread_once()使用(某个时间在整个程序中仅执行一次,不确定是那个线程)

    在多线程环境中,有些事仅需要执行一次.通常当初始化应用程序时,可以比较容易地将其放在main函数中.但当你写一个库时,就不能在main里面初始化了,你可以用静态初始化,但使用一次初始化(pthread ...

  8. Quartz Cron表达式 每周、每月执行一次

    原文:https://blog.csdn.net/qq_33432559/article/details/75633767 系统中通常有些需要自动执行的任务,这些任务可能每隔一段时间就要执行一次,也可 ...

  9. js函数只执行一次,函数重写,变量控制与闭包三种做法

    一.情景需求 调用后台接口需要附带token信息,那么在每个请求的头部添加token的做法就不太优雅了:一个网站请求100次,那就得写添加100次token,假设某天接口有所变动,改起来就十分麻烦了. ...

随机推荐

  1. Python 四种数值类型(int,long,float,complex)区别及转换

    Python支持四种不同的数值类型,包括int(整数)long(长整数)float(浮点实际值)complex (复数), 数字数据类型存储数值.他们是不可改变的数据类型,这意味着改变数字数据类型的结 ...

  2. Beta版本冲刺(一)

    目录 组员情况 组员1(组长):胡绪佩 组员3:庄卉 组员4:家灿 组员5:凯琳 组员6:翟丹丹 组员7:何家伟 组员8:政演 组员9:黄鸿杰 组员10:刘一好 组员11:何宇恒 展示组内最新成果 团 ...

  3. 谈vs2013单元测试感想

    (1)安装篇:这个就不用多说啦,百度一个安装包进行安装. 之前下载过vs2013当时是抱着玩玩的心态,也没有安装成功,现在作为作业重新安装,并且进行单元测试.下面就是安装vs2013的具体过程以及我遇 ...

  4. Bean的加载

    ClassPathXmlApplicationContext存储内容 为了更理解ApplicationContext,拿一个实例ClassPathXmlApplicationContext举例,看一下 ...

  5. SqlServer 获取字符串中小写字母的sql语句

    SQL字符串截取(SubString) 作用:返回第一个参数中从第二个参数指定的位置开始.第三个参数指定的长度的子字符串. 有时候我们会截取字符串中的一些特殊想要的东西,大小写字母.模号.汉字.数字等 ...

  6. [转帖]ESXi 网卡绑定 增加吞吐量的方法

    VMware ESX 5.0 网卡负载均衡配置3种方法 http://blog.chinaunix.net/uid-186064-id-3984942.html (1) 基于端口的负载均衡 (Rout ...

  7. [转帖]PG的简单备份恢复 找时间进行测试

    转帖PG的简单使用 https://blog.csdn.net/lk_db/article/details/77971634 一: 纯文件格式的脚本: 示例:1. 只导出postgres数据库的数据, ...

  8. vue组件间的数据和方法传递

    方法 1.父组件调用子组件:ref(在子组件中加上ref即可通过this.$refs.ref.method调用) 2.子组件调用父组件:emit(this.$emit(调用的方法名,传递的参数)) 数 ...

  9. 关于“代码规范”,“Review”和“Check list”(续)

    在前两天的    关于“代码规范”,“Review”和“Check list”    一文中,我给自己列出了Check list,如下: 1.代码能够工作么?它有没有实现预期的功能,逻辑是否正确等. ...

  10. 索引器 C#

    概述 索引器允许类或结构的实例就像数组一样进行索引. 索引器类似于属性,不同之处在于它们的访问器采用参数. 在下面的示例中,定义了一个泛型类,并为其提供了简单的 get 和 set 访问器方法(作为分 ...