Cron 作业调度
我的 Web 服务器中有两个 Cron 作业 -
*/5 0-3 * * 0-4 [my job]
*/5 19-23 * * 0-4 [my job]
我们位于 GMT+6 时区,服务器位于 GMT-8 时区。我们希望这项工作能够在
周日至周五 运行 GMT+6 时区上午 9 点至下午 5 点(办公时间) 每 5 分钟间隔
但 cron 作业似乎在周五运行,并在周日中午(GMT+6 时区)停止。
I have two Cron jobs in my web server -
*/5 0-3 * * 0-4 [my job]
*/5 19-23 * * 0-4 [my job]
We are in the GMT+6 timezone, and the server is in GMT-8 timezone. We would like the job to run -
Sunday to Friday
9 AM to 5 PM at GMT+6 timezone (office hours)
Every 5 minute interval
But it appears that the cron job runs on Fridays and also stops at Sunday noon at GMT+6 zone.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不知道有什么简单的方法可以更改时区。一些旧版本的
cron
支持名为CRON_TZ
的环境变量,但当前版本的cron
似乎不支持。所以你必须将时间转换为系统时间。
我认为你已经正确地计算了时间和日期,但你必须把它们放在一起。例如,星期四下午 5 点(UTC+6)是星期四凌晨 3 点(UTC-8),但您的规则在星期四没有运行任何内容。
根据我的计算,您想要:
您可以在 crontab 中将其表达为:
但是,此解决方案感觉不太好。
夏令时改变时会发生什么?您需要更新
crontab
吗?如果您拥有 root 访问权限,则可以修改 /etc/init.d/cron 条目并放入 TZ=America/Los_Angeles 或类似内容在那里呢?
当然,这个解决方案听起来也很糟糕,尤其是当其他人使用该系统时。如果您这样做,不妨更改系统的时区。
不幸的是,没有太多关于 cron 替代方案的建议
cron 的替代方案?
I'm not aware of any easy way to change the timezone. Some older versions of
cron
supported an environment variable calledCRON_TZ
, but the current version ofcron
doesn't seem to.So you'd have to convert the times to system time.
I think you have calculated the times correctly, and the days correctly, but you have to take them together. For example, 5pm on Thursday at UTC+6 is 3am on Thursday at UTC-8, but your rules aren't running anything on Thursday.
By my calculations, you want:
Which you would express in
crontab
as:This solution doesn't feel that good, however.
What happens when daylight savings changes? Will you need to update the
crontab
?Maybe if you have
root
access, you can modify the/etc/init.d/cron
entry and putTZ=America/Los_Angeles
or similar in there instead?Of course, that solution sounds bad too, especially if other people use the system. Might as well just change the system's time zone if you're doing that.
Unfortunately there's not a lot of suggestions for alternatives to cron
alternative to cron?
这篇文章帮助了我 http://starikovs.com/2011/12/21/ cron-时区问题/。
This article helped me http://starikovs.com/2011/12/21/cron-timezone-problem/.