如何设置CRON作业在Linux中每10秒运行一次?

时间:2021-10-09 05:27:38

I need to run a CRON job every 10 seconds from started time.

我需要从开始时间开始每隔10秒运行一次CRON作业。

In Linux how to run a CRON job on every 10 seconds from the time its started?

在Linux中如何从启动开始每隔10秒运行一次CRON作业?

I am trying to do as following-

我想按照以下方式做 -

when i make a request (or start) at 04:28:34 it should start at 04:28:44 not at 4:28:40

当我在04:28:34提出请求(或开始)它应该从04:28:44开始而不是在4:28:40

This is what i have done and i am trying,

这就是我所做的,我正在努力,

# m h  dom mon dow   command
*/10 * * * * /usr/bin/wget http://api.us/application/

What wrong have I made here to not work every 10 seconds?

我在这里犯了什么错,每10秒钟不工作?

2 个解决方案

#1


17  

To elaborate on Sougata Bose's answer, I think the OP wants a command to be run every 10 seconds from a start time; not 10 seconds after the first minute and every subsequent minute.

为了详细说明Sougata Bose的答案,我认为OP希望从开始时间开始每隔10秒运行一次命令;在第一分钟之后和之后的每一分钟之后不是10秒。

cron only has a resolution of 1 minute (there are other tools I think that may have finer resolutions but they are not standard on unix).

cron只有1分钟的分辨率(我认为还有其他工具可能有更好的分辨率,但它们不是unix的标准)。

Therefore, to resolve your issue you need 60 seconds / 10 seconds = 6 cron jobs, each with a sleep.

因此,要解决您的问题,您需要60秒/ 10秒= 6个cron作业,每个作业都有一个睡眠状态。

e.g. run crontab -e and add the following lines to your chosen editor:

例如运行crontab -e并将以下行添加到您选择的编辑器:

***** ( /usr/bin/wget http://api.us/application/ )  
***** ( sleep 10 ; /usr/bin/wget http://api.us/application/ )  
***** ( sleep 20 ; /usr/bin/wget http://api.us/application/ )  
***** ( sleep 30 ; /usr/bin/wget http://api.us/application/ )  
***** ( sleep 40 ; /usr/bin/wget http://api.us/application/ )  
***** ( sleep 50 ; /usr/bin/wget http://api.us/application/ )  

#2


4  

You have specified */10 in the minutes. Cron only allows for a minimum of one minute. You can try this -

您在分钟内指定了* / 10。 Cron只允许至少一分钟。你可以尝试这个 -

* * * * * ( sleep 10 ; /usr/bin/wget http://api.us/application/)

Which will execute it in every 10 seconds with sleep.

哪个会在睡眠时每10秒执行一次。

#1


17  

To elaborate on Sougata Bose's answer, I think the OP wants a command to be run every 10 seconds from a start time; not 10 seconds after the first minute and every subsequent minute.

为了详细说明Sougata Bose的答案,我认为OP希望从开始时间开始每隔10秒运行一次命令;在第一分钟之后和之后的每一分钟之后不是10秒。

cron only has a resolution of 1 minute (there are other tools I think that may have finer resolutions but they are not standard on unix).

cron只有1分钟的分辨率(我认为还有其他工具可能有更好的分辨率,但它们不是unix的标准)。

Therefore, to resolve your issue you need 60 seconds / 10 seconds = 6 cron jobs, each with a sleep.

因此,要解决您的问题,您需要60秒/ 10秒= 6个cron作业,每个作业都有一个睡眠状态。

e.g. run crontab -e and add the following lines to your chosen editor:

例如运行crontab -e并将以下行添加到您选择的编辑器:

***** ( /usr/bin/wget http://api.us/application/ )  
***** ( sleep 10 ; /usr/bin/wget http://api.us/application/ )  
***** ( sleep 20 ; /usr/bin/wget http://api.us/application/ )  
***** ( sleep 30 ; /usr/bin/wget http://api.us/application/ )  
***** ( sleep 40 ; /usr/bin/wget http://api.us/application/ )  
***** ( sleep 50 ; /usr/bin/wget http://api.us/application/ )  

#2


4  

You have specified */10 in the minutes. Cron only allows for a minimum of one minute. You can try this -

您在分钟内指定了* / 10。 Cron只允许至少一分钟。你可以尝试这个 -

* * * * * ( sleep 10 ; /usr/bin/wget http://api.us/application/)

Which will execute it in every 10 seconds with sleep.

哪个会在睡眠时每10秒执行一次。