更改 cronjob 的时区

qai*_*urn 10 shell cron timezone

我有一个 cronjob,每天在 UTC 时间上午 9:00 执行。我在 GMT+1,所以它在当地时间上午 10:00 执行。当时区发生变化(到夏令时,DST)时,cronjob 仍然在 UTC 时间上午 9:00 执行,但在当地时间上午 11:00 执行。但我希望它总是在 10:00 执行,无论夏令时与否。我怎么做?

jor*_*anm 6

这可能取决于您的操作系统及其对cron. 这在最流行的 cron 实现中是不可能的,vixie/isc cron. 来自crontab(5) manpage

LIMITATIONS
       The  cron  daemon  runs with a defined timezone. It currently does not 
       support per-user timezones. All the tasks: system's and user's will 
       be run based on the configured timezone. Even if a user specifies  
       the TZ  environment  variable  in  his crontab this will affect only 
       the commands executed in the crontab, not the execution of the crontab 
       tasks themselves.
Run Code Online (Sandbox Code Playgroud)


小智 2

检查 /etc/timezone 中的设置。在您提到的问题中,您所在的位置是“GMT+1”,如果您的时区设置为“GMT+1”,那么您的脚本将始终在 UTC 加一小时执行。如果设置为例如“欧洲/巴黎”,则执行时间将随着夏令时而变化。