每30秒运行一次cron [英] Running a cron every 30 seconds

查看:2148
本文介绍了每30秒运行一次cron的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好,所以我有一个cron,我需要运行每30秒...这里是我有以下

Ok so i have a cron that i need to run every 30 seconds...here is what i have below

*/30 * * * * /bin/bash -l -c 'cd /srv/last_song/releases/20120308133159 && script/rails runner -e production '\''Song.insert_latest'\'''

它运行,但是这是30分钟或30秒...而且我一直在读,如果我经常运行它可能不是最好的工具使用。有没有另一个更好的工具,我可以安装在ubuntu 11.04上,这将是一个更好的选择或有一种方法来修复上述cron

It runs but is this 30 minutes or 30 seconds...and also I have been reading that cron might not be the best tool to use if I run it that often. Is there another better tool that i can install on ubuntu 11.04 that will be a better option or is there a way to fix the above cron

推荐答案

您在分钟说明符中有 * / 30 - 表示每分钟,但步长为30(换句话说,小时)。由于 cron 没有下降到分钟的分辨率,你将需要另一种方式。

You have */30 in the minutes specifier - that means every minute but with a step of 30 (in other words, every half hour). Since cron does not go down to sub-minute resolutions, you will need to find another way.

,虽然它有点kludge,是有两个工作,一个偏移30秒:

One possibility, though it's a bit of a kludge, is to have two jobs, one offset by 30 seconds:

* * * * * /path/to/executable param1 param2
* * * * * ( sleep 30 ; /path/to/executable param1 param2 )

两个 cron 工作实际上是每分钟运行一次,但后者将等待半分钟,然后执行作业的肉, / path / to / executable

Both cron jobs actually run every minute but the latter one will wait half a minute before executing the "meat" of the job, /path/to/executable.

这篇关于每30秒运行一次cron的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆