linux 秒级别定时任务 crond shell while
2017-03-01 09:44
656 查看
第一种方案,当然是写一个后台运行的脚本一直循环,然后每次循环sleep一段时间。
while true ;do
command
sleep XX //间隔秒数
done
第二种方案,使用crontab。
我们都知道crontab的粒度最小是到分钟,但是我们还是可以通过变通的方法做到隔多少秒运行一次。
以下方法将每20秒执行一次
crontab -e
* * * * * /bin/date
* * * * * sleep 20; /bin/date
* * * * * sleep 40; /bin/date
说明:需要将/bin/date更换成你的命令即可
这种做法去处理隔几十秒的定时任务还好,要是每1秒运行一次就得添加60条记录。。。如果每秒运行还是用方案一吧。
while true ;do
command
sleep XX //间隔秒数
done
第二种方案,使用crontab。
我们都知道crontab的粒度最小是到分钟,但是我们还是可以通过变通的方法做到隔多少秒运行一次。
以下方法将每20秒执行一次
crontab -e
* * * * * /bin/date
* * * * * sleep 20; /bin/date
* * * * * sleep 40; /bin/date
说明:需要将/bin/date更换成你的命令即可
这种做法去处理隔几十秒的定时任务还好,要是每1秒运行一次就得添加60条记录。。。如果每秒运行还是用方案一吧。
相关文章推荐
- 第十八天-linux系统定时任务crond深入实战
- Linux下利用Crond和Expect定时登陆交换机执行任务
- 实战-----使用crond 在linux中定时执行任务
- linux下定时执行计划crond任务
- linux中shell定时任务执行oracle备份
- linux 定时任务 crond
- linux下环境变量和crond定时任务 和svn钩子
- linux真正使用shell脚本做定时任务 关键的Nohup
- Linux基础系列(六)Linux系统定时任务Crond
- Linux定时任务 - atd和crond
- Linux -- Crond 定时任务
- linux定时任务crond服务详细说明
- Linux定时任务crontab每三秒执行一次shell
- linux crond 定时任务
- 使用crond 在linux中定时执行任务
- 使用crond和at 在linux中定时执行任务
- linux下定时执行计划crond任务
- Linux shell crontab expdp 定时任务逻辑备份
- Linux定时任务--crond服务
- 使用crond和at 在linux中定时执行任务