如何在每月的最后一秒运行 crontab?
我需要 crontab 运行一个脚本,在本月的最后一秒将信息从 mysql 中的表传输到另一个表。 (该月最后一天的最后一秒)。
crontab 执行的目的是什么?
谢谢。
I need crontab to run a script that transfers info from a table in mysql to another table at the last second the month. (The last second of the last day of the month).
What would the crontab execution be for this?
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不确定这是否可以以通用方式完成,因为该月的最后一天有所不同,并且据我所知, crontab 语法没有为该用例提供任何内容。
您可能需要自己找出正确的日期,并将各个作业(具有完整的日期和时间,即每年 12 个)添加到 crontab。
但你首先需要这个做什么?这听起来有点像“气味”,因为如果你在最后一秒开始工作,你就不能真正依赖任何工作在月底之前完成。每个月第一天的 0:00 执行不是更容易吗?
盗自这个答案 关于服务器故障:
Not sure this can be done in a generic way, because the last day of the month varies and as far as I can see, the crontab syntax does not offer anything for that use case.
You may have to find out the correct date for yourself, and add individual jobs (with full dates and times, i.e. 12 per year) to the crontab.
But what do you need this for in the first place? It sounds a bit like a "smell" because you can't really rely on any job being finished before the end of the month if you start it in the last second. Would executing it at 0:00 every first day of the month not be much easier?
Stolen from this answer on Serverfault:
这将为您提供您正在寻找的内容(精确到分钟 - 而不是秒)。只需将我提到的 crontab 时间调整为 59 23 ( http://sudobash.net/?p=424 )
Cron:
脚本:
This will get you exactly what you are looking for (down to the minute - not the second). Just adjust the crontab time I mention to be 59 23 ( http://sudobash.net/?p=424 )
Cron:
Script: