Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/24.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/docker/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 如果向crontab添加每10分钟重复一次的命令,那么第一个作业何时运行?_Linux_Docker_Cron - Fatal编程技术网

Linux 如果向crontab添加每10分钟重复一次的命令,那么第一个作业何时运行?

Linux 如果向crontab添加每10分钟重复一次的命令,那么第一个作业何时运行?,linux,docker,cron,Linux,Docker,Cron,作为docker容器设置的一部分,将以下内容注入到crontab中: */10 * * * * /opt/run.sh >> /opt/run_log.log 根据crontab的行为,第一次跑步应该在什么时候开始?10分钟的周期应该立即开始,还是在放入crontab后10分钟开始。这两种行为都没有发生,因此我试图通过理解预期的行为来更深入地调试它。这个cron沙盒模拟器为您提供了一个想法: Mins Hrs Day Mth DoW */10 * * * *

作为docker容器设置的一部分,将以下内容注入到crontab中:

*/10 * * * * /opt/run.sh >> /opt/run_log.log

根据crontab的行为,第一次跑步应该在什么时候开始?10分钟的周期应该立即开始,还是在放入crontab后10分钟开始。这两种行为都没有发生,因此我试图通过理解预期的行为来更深入地调试它。

这个cron沙盒模拟器为您提供了一个想法:

Mins    Hrs Day Mth DoW
*/10    *   *   *   *

This run time (UTC)     Sat 2016-Jan-23 0653
Forward Schedule    Sat 2016-Jan-23 0700
    Sat 2016-Jan-23 0710
    Sat 2016-Jan-23 0720
它使用以下语法:

第n个“0-23/n”每隔一次,“
*/2”每隔一次。
*/1
”在其他地方通常是可以接受的,但在这里被标记为可能是意外输入


例如,参见“”(by)

让我们创建一个名为“
crontab
”的新文件来描述我们的工作

下面的DockerFile描述了构建映像的所有步骤

然后,您可以使用

然后运行它:

耐心等待2分钟,您的命令行应显示:


如果将第一个“”替换为“/10”,则必须等待下一个0、10或20或。。。它将在0、10、20、,。。一点五十分。
* * * * * root echo "Hello world" >> /var/log/cron.log 2>&1
# An empty line is required at the end of this file for a valid cron file.
FROM ubuntu:latest
MAINTAINER docker@ekito.fr

# Add crontab file in the cron directory
ADD crontab /etc/cron.d/hello-cron

# Give execution rights on the cron job
RUN chmod 0644 /etc/cron.d/hello-cron

# Create the log file to be able to run tail
RUN touch /var/log/cron.log

# Run the command on container startup
CMD cron && tail -f /var/log/cron.log
sudo docker build --rm -t ekito/cron-example .
sudo docker run -t -i ekito/cron-example
Hello world
Hello world