第一个作业何时运行

第一个作业何时运行

本文介绍了如果添加一个每10分钟重复一次的命令到crontab,第一个作业何时运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 作为docker容器设置的一部分,以下内容注入到crontab中: * / 10 * * * * /opt/run.sh>> /opt/run_log.log 根据crontab的行为,第一次运行应该何时开始?如果10分钟的周期立即开始,或者10分钟后,它被放入crontab。 解决方案这个cron沙箱模拟器给你一个想法: Mins Hrs Day Mth DoW * / 10 * * * * 此运行时间(UTC)2016年1月 - 2016年1月23 0653 前进计划2016年1月23日0700 2016年1月23日$ 10 2016年1月 - 23 0720 它使用语法: 每个 nth'0-23 / n',' * / 2 ' * / 1 '在其他地方一般可以接受,但在这里被标记为可能是非预期的条目。 查看例如使用Docker运行cron作业(通过 Julien Boulay ) 让我们创建一个名为 crontab 来描述我们的工作。 * * * * * root echoHello world >> /var/log/cron.log 2>& 1 #对于有效的cron文件,在此文件的结尾处需要一个空行。 以下DockerFile描述了构建图像的所有步骤 FROM ubuntu:latest MAINTAINER docker@ekito.fr #在cron目录中添加crontab文件 ADD crontab /etc/cron.d/hello-cron #为cron作业提供执行权限 RUN chmod 0644 / etc /cron.d/hello-cron #创建能够运行尾部的日志文件 RUN touch /var/log/cron.log #在容器启动时运行命令 CMD cron&& tail -f /var/log/cron.log 用 构建映像。sudo docker build --rm -t ekito / cron-example。 并运行: sudo docker run -t -i ekito / cron-example $ p Hello world Hello world 如果您以 / 10取代第一个'',您必须等到下一个0或10或20或...小时。 As part of the setup of a docker container, the following gets injected into crontab:*/10 * * * * /opt/run.sh >> /opt/run_log.logAccording to the behavior of crontab, when should the first run kick off? Should the 10 minute cycle begin instantly, or 10 minutes after this is put into crontab. Neither behavior is happening so I am trying to debug this in more depth by trying to understand the intended behavior. 解决方案 This cron sandbox simulator gives you an idea:Mins Hrs Day Mth DoW*/10 * * * *This run time (UTC) Sat 2016-Jan-23 0653Forward Schedule Sat 2016-Jan-23 0700 Sat 2016-Jan-23 0710 Sat 2016-Jan-23 0720It uses the syntax: Every nth '0-23/n', '*/2' would be every other. '*/1' is generally acceptable elsewhere, but is flagged here as possibly an unintended entry.See for example "Run a cron job with Docker" (by Julien Boulay) Let’s create a new file called "crontab" to describe our job.* * * * * 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. The following DockerFile describes all the steps to build your imageFROM ubuntu:latestMAINTAINER docker@ekito.fr# Add crontab file in the cron directoryADD crontab /etc/cron.d/hello-cron# Give execution rights on the cron jobRUN chmod 0644 /etc/cron.d/hello-cron# Create the log file to be able to run tailRUN touch /var/log/cron.log# Run the command on container startupCMD cron && tail -f /var/log/cron.log Then you can build the image withsudo docker build --rm -t ekito/cron-example . And run it:sudo docker run -t -i ekito/cron-example Be patient, wait for 2 minutes and your commandline should display:Hello worldHello worldIf you replaced the first '' by '/10', you would have to wait to the next 0 or 10 or 20 or... of the hour. 这篇关于如果添加一个每10分钟重复一次的命令到crontab,第一个作业何时运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-15 20:21