2

We are trying to schedule a script to run at 9am ET every day throughout the year, regardless of daylight savings. On our GCP Compute Engine / Linux Server, cron runs in UTC always. It is easy enough to adjust -4 or -5 hours to run in ET, however the issue of daylight savings is (mildly) problematic, as we have to change the cron time by +/- 1 hour at daylight savings for it to remain at 9am ET.

In R, rather than using EDT, we can set the timezone environment to America/New_York, which seems to account automatically for daylight savings, always running at 9am regardless of EDT vs EST. Is there anyway to schedule in cron so that something runs at 9am ET always?

1 Answer 1

1

Try setting both of these in your cron:

CRON_TZ='America/New_York'

TZ='America/New_York'

EDIT: you can put the shell file wherever you like.

  1. On the tar line, you'll enter the command you need executed (be it a script or whatever).
  2. crontab -e and type the CRON_TZ=<YOUR/TZ>
  3. Right below CRON_TZ you point to the location of the shell script/command you want executed.

Remember to make sure that the script is executable.

5
  • 1
    wow had no idea there is a TZ option for cron, this is great. Do you think I need to use both of these? Or just one and you're not sure which?
    – Canovice
    Commented Sep 4, 2022 at 15:41
  • 1
    It should work. The reason you'll need both is that one is for setting cron's timezone, while the other one is for setting the jobs' timezone. If that doesn't work, you'll have to wrap the timezone in a script which executes cron. Please let me know if it doesn't work and I'll try to sort you out.
    – telometto
    Commented Sep 4, 2022 at 15:51
  • This is not working, still runs in UTC. I am giving linuxhint.com/set-timezone-crontab a try
    – Canovice
    Commented Sep 5, 2022 at 12:56
  • @Canovice Ah, I see you found a guide online. I took a quick glance at it and it is more or less what I was thinking of. Please see my (updated) answer to continue where you are struggling.
    – telometto
    Commented Sep 5, 2022 at 15:57
  • 1
    Seems like I've got it working now!
    – Canovice
    Commented Sep 5, 2022 at 17:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .