不同时区的 Cron 作业 [英] Cron job in a different timezone
问题描述
有没有办法为特定时区设置定时任务?
Is there a way of setting up a cronjob for a specific timezone?
我的共享主机在美国(弗吉尼亚州),而我在英国.如果我将 cron 作业设置为在每个星期五的 1600 小时执行,那么它将在弗吉尼亚州的 1600 时执行.
My shared hosting is in USA (Virginia) and I am in UK. If I set a cron job to be executed at 1600 hrs every friday, then it will execute when its 1600 in Virginia.
我想知道我是否可以设置我的 cronjob 以使其了解选择哪个时区.我不太担心夏令时的差异.
I was wondering if I can setup my cronjob in such a way that it understands which timezone to pick. I am not too worried about daylight saving difference.
我已经问过我的共享托管服务提供商,他们说我应该能够在一些 cron ini 文件中设置时区,但我找不到任何.
I have asked my shared hosting providers about it and they said I should be able to set the timezone in some cron ini files, but I could not find any.
推荐答案
我觉得你应该检查一下
I think that you should check
/etc/default/cron
或者直接输入
Crontab cronfile
你应该找到
TZ=UTC
这应该改变(例如 America/New_York).第二种方式在cron示例中设置
This should be changed (for example America/New_York). Second way is set in cron example
5 2 3 * * TZ="America/New_York" /do/command > /dev/null 2>&1
这篇关于不同时区的 Cron 作业的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!