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,假设某天接口有所变动,改起来就十分麻烦了. ...
随机推荐
- 为什么java的main方法必须是静态的
今天看类型信息时发现一个问题,不能再main方法中打印this关键字的信息,这时想起了之前的知识,不能再静态方法中调用this.理由很简单,this表示“这个对象”,也就是声明一个类的对象,然而静态方 ...
- WPF使用路径(URI)引用资源文件
Uri uri = new Uri("pack://application:,,,/程序集名称;component/Resources/bj.png", UriKind.Absol ...
- jsonp 接口
一.请求接口 <script type="text/javascript" src="js/jquery.min.js"></script&g ...
- linux 取消控制台报警音
可以通过setterm -blength 0 设置报警音报警时间,0表示没有报警音 也可以通过setterm -bfreq 10 设置报警音的频率(Hz) 如果通过命令行直接设置,当下会生效,但是重启 ...
- json-server(copy)
https://blog.csdn.net/wangle_style/article/details/79455508(原文章地址) 新版vue-cli如何使用json-server来mork 原创 ...
- Go语言?Docker?对新技术怎么看?
对于 Go 语言和 Docker 这两种技术,在国内的技术圈中有相当大的一部分人和群体还在持观望或是不信任的态度.所以,我想写这篇文章,从两个方面来论述一下我的观点和看法. 上个月,作为 Go 语言的 ...
- LeetCode 5回文数
判断一个整数是否是回文数.回文数是指正序(从左向右)和倒序(从右向左)读都是一样的整数. 示例 1: 输入: 121 输出: true 示例 2: 输入: -121 输出: false 解释: 从左向 ...
- jsoncpp的安装与使用示例
安装: 生成静态库 生成静态库: 第一步:生成目标文件: g++ -g -Wall -c json_reader.cpp json_value.cpp json_writer.cpp -I. -I.. ...
- Qt error ------ 'XXX' has not been declared
1.头文件没加 2.调用函数者的头文件在XXX头文件的下方
- 使用Sql语句快速将数据表转换成实体类
开发过程中经常需要根据数据表编写对应的实体类,下面是使用sql语句快速将数据表转换成对应实体类的代码,使用时只需要将第一行'TableName'引号里面的字母换成具体的表名称就行了: declare ...