Score:3

Run cronjobs in different timezones

wf flag

I have some cronjobs that I want to run. I want two of my scripts to run in UTC and the rest in CET. I have tried with cron_tz but it does not seem to work.

user535733 avatar
cn flag
Seems like a duplicate of https://serverfault.com/questions/374284
Score:3
cn flag
CRON_TZ=Europe/Amsterdam 

works. Mind though that it could be that specific Ubuntu's do not work with CRON_TZ. man 5 crontab tells you if it is supported. If it does not have this, then yours does not support it:

The CRON_TZ variable specifies the time zone specific for the cron table. The user should enter a time according to the specified time zone into the table. The time used for writing into a log file is taken from the local time zone, where the daemon is running.

It probably does not and you should be using systemd.timer and systemd.time and calendar events. Each unit holds its own timezomne so that will fix your problem.

needHelpToCode avatar
wf flag
I used CRON_TZ with capitals but thanks for the manual direction.
cn flag
@needHelpToCode Ill remove it :D
needHelpToCode avatar
wf flag
right now I have a script like * * * * * CRON_TZ=UTC etc.., is this the way that it works?
cn flag
no. CRON_TZ goes in a seperate line at the beginning of cron file (similar to PATH) if you want the SCRIPTS to run with a diff. timezone use @vidarlo answer. You can use TZ=UTC before the script to have the script use another timezone. Feel free to remove the upvote and upvote vidarlo ;)
Score:2
om flag

Preface the command with TZ=CET, or set the TZ environment variable

[~]$ TZ=UTC date
Thu Dec 15 14:53:51 UTC 2022
[~]$ TZ=CET date
Thu Dec 15 15:53:54 CET 2022
cn flag
are you sure? afaik TZ only affects the scripts executed (so the TZ inside the scripts is set) and not when cron starts it.
vidarlo avatar
om flag
I think the confusion is what he wants. I read the question as he wanting to run *the commands* in different timezones, not the *cron* itself.
cn flag
hmmm :) that is one way of reading it yes _O- I focused too much on CRON_TZ
vidarlo avatar
om flag
Probably means the question is somewhat unclear ;)
Raffa avatar
jp flag
+1 ... Possible to read it that way
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.