Chinaunix

标题: crontab里能设置每秒执行一次么? [打印本页]

作者: Hendane    时间: 2011-05-05 11:42
标题: crontab里能设置每秒执行一次么?
RT
crontab里能不能设置每秒钟执行一次脚本?
作者: jinguzhong    时间: 2011-05-05 14:52
你可以这样做:
写一个shell,在shell里实现每秒执行一次脚本内容,里面可以设置执行次数,或设置执行结束时间,crontab只设置启动shell的时间。
作者: iceblood    时间: 2011-05-05 14:58
RT
crontab里能不能设置每秒钟执行一次脚本?
Hendane 发表于 2011-05-05 11:42



    这个有意义吗?
作者: cst05001    时间: 2011-05-05 15:22
用脚本实现。crontab实现不了。
作者: 落英飘风香    时间: 2011-05-05 15:59
我的印象中crontab只是设置启动shell的时间吧?
作者: hq262866869    时间: 2011-05-05 16:23
本帖最后由 hq262866869 于 2011-05-05 16:42 编辑

#crontab -e
*/1 * * * *  command
作者: cst05001    时间: 2011-05-05 16:44
回复 6# hq262866869


    同学,这是分钟……
分 时 日 月 星期
作者: chenyx    时间: 2011-05-05 16:50
crontab最短只能是分钟
作者: hq262866869    时间: 2011-05-05 16:54
回复 7# cst05001


    SORRY~~没看清~~{:3_184:}
作者: vermouth    时间: 2011-05-05 21:38
脚本里 sleep 1 ; do 循环么。
作者: Hendane    时间: 2011-05-06 08:35
回复 10# vermouth


    如何实现?
作者: vermouth    时间: 2011-05-06 09:27
回复 11# Hendane

做循环么,中间加上 sleep 1 就是等一秒,然后再运行。
作者: cst05001    时间: 2011-05-06 09:34
回复 10# vermouth


    我觉得也是……
作者: mef777    时间: 2011-05-06 10:52
在脚本里加个循环不就得了。crontab只能实现分钟级的粒度

分 时 日 月 周   命令
作者: shplpy    时间: 2011-05-06 15:37
RT
crontab里能不能设置每秒钟执行一次脚本?
Hendane 发表于 2011-05-05 11:42



* * * * *  command
* * * * * sleep 1 &&  command
* * * * * sleep 2 &&  command
* * * * * sleep 3 &&  command
....
* * * * * sleep 59 && command
作者: gnah    时间: 2011-05-07 09:11
*/60 * * * *

这样不可以吗?
作者: 是我别封号    时间: 2011-05-07 10:14
*/60 * * * *

这样不可以吗?
gnah 发表于 2011-05-07 09:11



    正解
作者: shplpy    时间: 2011-05-07 13:16
正解
是我别封号 发表于 2011-05-07 10:14



    正解?不知你测试过没有,我试了是不行
作者: shplpy    时间: 2011-05-07 13:20
*/60 * * * *

这样不可以吗?
gnah 发表于 2011-05-07 09:11



    不可以
作者: 是我别封号    时间: 2011-05-07 15:49
之前试过1/30

下周试出结果再来
作者: yifangyou    时间: 2011-05-07 18:03
shell实现秒级crontab计划任务
http://blog.chinaunix.net/space. ... =blog&id=274490
作者: shplpy    时间: 2011-05-07 20:05
shell实现秒级crontab计划任务
yifangyou 发表于 2011-05-07 18:03



    方法有点复杂,不如我说的方法来的直观简单,不过还是不错的
作者: Shell_HAT    时间: 2011-05-07 21:36
回复 15# shplpy


这样crontab里面的东西看着好乱啊,新建一个脚本,在这个脚本里面sleep
作者: shplpy    时间: 2011-05-07 23:55
回复  shplpy


这样crontab里面的东西看着好乱啊,新建一个脚本,在这个脚本里面sleep
Shell_HAT 发表于 2011-05-07 21:36



    但是觉得放在脚本里面多少会有时间差,没有这个精确
作者: haishui    时间: 2011-05-08 00:18
写个shell的脚本吧!
作者: yyjandlc    时间: 2011-05-08 18:40
脚本里面写循环
然后nohup这个脚本呗
没必要一定在crontab里面吧
作者: lq2003    时间: 2011-05-09 11:30
本帖最后由 lq2003 于 2011-05-09 11:40 编辑
#crontab -e
*/1 * * * *  command
hq262866869 发表于 2011-05-05 16:23



*  和  */1 是有区别的.
作者: lq2003    时间: 2011-05-09 11:35
Ranges of numbers are allowed.  Ranges are two numbers separated with a hyphen.  The  specified
       range  is inclusive.  For example, 8-11 for an "hours" entry specifies execution at hours 8, 9,
       10 and 11.

       Lists are allowed.  A list is a set of numbers (or  ranges)  separated  by  commas.   Examples:
       "1,2,5,9", "0-4,8-12".

       Step  values  can be used in conjunction with ranges.  Following a range with "<number>" speci-
       fies skips of the number’s value through the range.  For example, "0-23/2" can be used  in  the
       hours  field  to specify command execution every other hour (the alternative in the V7 standard
       is "0,2,4,6,8,10,12,14,16,18,20,22").  Steps are also permitted after an asterisk,  so  if  you
       want to say "every two hours", just use "*/2".
作者: whsalex    时间: 2011-05-09 13:24
corntab最低只支持1"分钟"
作者: shplpy    时间: 2011-05-09 16:08
*  和  */1 是有区别的.
lq2003 发表于 2011-05-09 11:30



    * * * * * command和*/1 * * * *  command有区别?请问是啥区别呢
作者: maochanglu    时间: 2011-05-09 20:17
cron 只能定到分钟。
作者: 不想在家喂猪    时间: 2011-05-09 22:51
每秒执行一次cron,不耗资源么?
作者: 极北之北    时间: 2011-05-10 10:17
提示: 作者被禁止或删除 内容自动屏蔽
作者: virges    时间: 2011-05-10 10:31
计划不到一秒这种粒度
作者: hackmail    时间: 2011-05-10 13:23
60/1 * * * * command
作者: riwuyou    时间: 2011-05-10 14:20
好像是这样一个道理
作者: 极北之北    时间: 2011-05-10 15:16
提示: 作者被禁止或删除 内容自动屏蔽
作者: gao_linfeng    时间: 2011-05-11 09:39
回复 1# Hendane


while :;do <commander>;sleep 1s;done
作者: Steiny    时间: 2011-05-12 13:23
60/1 * * * * command
hackmail 发表于 2011-05-10 13:23



    不对,看原文解释:

The forward slash (/) can be used to specify step values. The value of an integer can be skipped within a range by following the range with /<integer>. For example, 0-59/2 can be used to define every other minute in the minute field. Step values can also be used with an asterisk. For instance, the value */3 can be used in the month field to run the task every third month.


况且,分定位不能大于59这个数字。
作者: theone5288    时间: 2011-05-12 13:55
小心当机啊!!!
作者: thanks_chen    时间: 2011-05-13 13:15
crontab  知道分,还真没没有秒这么精确!
作者: hugehawk    时间: 2011-05-13 16:09
RT
crontab里能不能设置每秒钟执行一次脚本?
Hendane 发表于 2011-05-05 11:42



    你在shell环境下这么使用cron,有意义吗?如果你非要这么做,很有可能造成你的脚本在执行时出错误,这是shell自身的缺陷造成的。
作者: msscisd    时间: 2011-05-15 22:06
提示: 作者被禁止或删除 内容自动屏蔽
作者: ttldreams    时间: 2011-05-17 20:38
mark
作者: 狂热追求者    时间: 2011-05-24 11:05
我觉得15楼的应该可以 自己用这个方法做过十秒一次的
既然*/1 * * * * command 不行的话

*/* * * * * command行不行呢 我没试过 哪位试过发上来
作者: elemtype    时间: 2011-05-24 12:16
crontab是分钟级别的,源代码就是这么实现的.
可以写个shell,sleep
有没有什么副作用,试下才知道.
作者: zhiwood    时间: 2011-05-24 22:13
不要用cron了,用watch好了.

  1. watch -n 1 ls -l
复制代码

作者: newyue    时间: 2011-05-30 15:06
我觉得设置到秒完全没必要啊,如果设置到秒的话,一个系统负载增大,二是程序的执行时间万一超过设定的秒数,很可能造成死循环啊~




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2