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,假设某天接口有所变动,改起来就十分麻烦了. ...
随机推荐
- 集美大学1414班软件工程个人作业2——个人作业2:APP案例分析
一.作业链接 个人作业2:APP案例分析 二.博文要求 通过分析你选中的产品,结合阅读<构建之法>,写一篇随笔,包含下述三个环节的所有要求. 第一部分 调研, 评测 下载软件并使用起来, ...
- VS2013的安装与测试
第一步:下载完成之后点击安装,在安装过程中会出现很多选择,选择社区版(c++),安装完成: 第二步:安装完成之后打开VS2013,如图所示: 第三步:按以下步骤进行 第四步:点击[OK]之后 第五 ...
- PAT 1048 数字加密
https://pintia.cn/problem-sets/994805260223102976/problems/994805276438282240 本题要求实现一种数字加密方法.首先固定一个加 ...
- html+css照片墙
html文件 <!DOCTYPE html><html lang="en"><head> <meta charset="UTF- ...
- sql 索引 sql_safe_updates
为了数据的安全性,mysql有一个安全性设置,sql_safe_updates ,当把这个值设置成1的时候,当程序要对数据进行修改删除操作的时候条件必须要走索引. 刚好现在也碰到了此类问题:网上找了相 ...
- CentOS修改主机名字
目录 查看hostnmae 修改hostname 远程别名/etc/hosts 查看hostnmae [root@centos ~]$ hostname centos 修改hostname [root ...
- springMVC下出现http 400错误
参数绑定过程中类型转换失败 Failed to convert property value of type 'java.lang.String' to required type 'java.uti ...
- MyBatis分步查询的延迟加载
延迟加载的概念只存在于分步查询时: 延迟加载的本质是为第一步查询返回的Java Bean创建了一个代理对象: 延迟加载的全局设置有两个: lazyLoadingEnabled,作用为设置select语 ...
- Cuba项目从远程Git仓库下载步骤
Cuba Studio 从Git远程仓库里下载代码,并且可以使用IDEA打开,需要注意的地方: 1.使用Git Gui克隆代码 也可以使用IDEA本身集成的Git下载,但是要保证:下载了项目以后,不能 ...
- MySQL的replace方法
mysql中replace函数直接替换mysql数据库中某字段中的特定字符串,不再需要自己写函数去替换,用起来非常的方便,mysql 替换函数replace()Update `table_name` ...