crontab每10秒钟执行一次
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秒钟执行一次的更多相关文章
- Linux定时任务crontab每三秒执行一次shell
第一种方法:当然首先想到的是写一个触发的脚本,在触发脚本中使用死循环来解决此问题,如下: cat kick.sh #!/bin/bash while : ;do /home/somedir/scrip ...
- linux crontab & 每隔10秒执行一次
linux下定时执行任务的方法 在LINUX中你应该先输入crontab -e,然后就会有个vi编辑界面,再输入0 3 * * 1 /clearigame2内容到里面 :wq 保存退出. 在LINU ...
- Crontab中shell每分钟执行一次HDFS文件上传不执行的解决方案
一.Crontab -e 加入输出Log */1 * * * * /qiwen_list/upload_to_hdfs.sh > /qiwen_list/mapred.log 2>& ...
- cron和crontab命令详解 crontab 每分钟、每小时、每天、每周、每月、每年定时执行 crontab每5分钟执行一次
cron机制 cron可以让系统在指定的时间,去执行某个指定的工作,我们可以使用crontab指令来管理cron机制 crontab参数 -u:这个参数可以让我们去编辑其他 ...
- linux定时任务crontab 实现如何每秒执行一次!
linux crontab 命令,最小的执行时间是一分钟.如需要在小于一分钟内重复执行,可以有两个方法实现. Cron 各项的描述 以下是 crontab 文件的格式: {minute} {hour} ...
- ubuntu crontab 在时间段内随机执行一次
crontab 在linux下做定时任务的命令, 1. 基本格式 * * * * * cmd 第一个表示:分钟 1-59, 每分钟用 */1 第二个表示:小时 023 第三个表示:日期1-31 第四个 ...
- pthread_once()使用(某个时间在整个程序中仅执行一次,不确定是那个线程)
在多线程环境中,有些事仅需要执行一次.通常当初始化应用程序时,可以比较容易地将其放在main函数中.但当你写一个库时,就不能在main里面初始化了,你可以用静态初始化,但使用一次初始化(pthread ...
- Quartz Cron表达式 每周、每月执行一次
原文:https://blog.csdn.net/qq_33432559/article/details/75633767 系统中通常有些需要自动执行的任务,这些任务可能每隔一段时间就要执行一次,也可 ...
- js函数只执行一次,函数重写,变量控制与闭包三种做法
一.情景需求 调用后台接口需要附带token信息,那么在每个请求的头部添加token的做法就不太优雅了:一个网站请求100次,那就得写添加100次token,假设某天接口有所变动,改起来就十分麻烦了. ...
随机推荐
- [转帖]devops 容器管理平台 rancher 简介
https://testerhome.com/topics/10828 chenhengjie123 for PPmoney · 2017年11月13日 · 最后由 c19950809 回复于 201 ...
- PSP(4.13——4.19)以及周记录
1.PSP 4.13 15:15 15:30 0 15 站立会议 A Y min 15:30 19:00 65 145 Account A Y min 21:15 23:00 15 90 博客 B Y ...
- Vue---导航守卫使用方法详解
导航守卫 正如其名,vue-router 提供的导航守卫主要用来通过跳转或取消的方式守卫导航.有多种机会植入路由导航过程中:全局的, 单个路由独享的, 或者组件级的. 记住参数或查询的改变并不会触发进 ...
- Before NOIP2017
明天就比赛了呢! 说起来,这是我第二次,可能也是最后一次正式参加提高组的比赛了. 虽然是从初中就有参加信息学的学习,但是认真学习信息竞赛还是去年七月开始的.NOIP2016 中,我凭着两天的简单题和一 ...
- bzoj4514 [Sdoi2016]数字配对(网络流)
Description 有 n 种数字,第 i 种数字是 ai.有 bi 个,权值是 ci. 若两个数字 ai.aj 满足,ai 是 aj 的倍数,且 ai/aj 是一个质数, 那么这两个数字可以配对 ...
- Spring中ClassPathXmlApplication与FileSystemXmlApplicationContext的区别以及ClassPathXmlApplicationContext 的具体路径
一.ClassPathXmlApplicationContext 的具体路径 String s[] = System.getProperty("java.class.path"). ...
- MT【81】含参数三次函数因式分解
解答: 评:这题实质上是对关于$x$的三次函数进行了一个因式分解.这种把$a$看成主元的技巧是初中处理高次的因式分解的常用技巧.如果用三次求导去做计算量比较大,要计算极值.
- 【题解】 bzoj2748 [HAOI2012]音量调节 (动态规划)
懒得复制,戳我戳我 Solution: 傻逼题目,直接dp就可以了,他是求最后一次的最大值 Code: //It is coded by Ning_Mew on 4.17 #include<bi ...
- Java中public、private、protect对数据成员或成员函数的访问限制
Java类中对数据成员.成员函数的访问限制修饰有:public.protect.private.friendly(包访问限制) public修饰的数据成员或成员函数是对所有用户开放的,所有用户可以直接 ...
- Java实现的一个简单的模板渲染
代码 package com.hdwang; import java.util.HashMap; import java.util.Map; /** * Created by hdwang on 20 ...