Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

489
Views
Is it possible to configure a crontab to adjust its times when daylight savings time is in effect?

I have a crontab scheduling many things on an Ubuntu server which runs on UTC time. Some of the scripts being run are time sensitive in relation to the web applications they are providing functionality for.

e.g. Something has to be updated at 4pm every day, as the end users see it by their clock.

This is not an issue during the winter when the UK is on GMT, but from April to October, the clocks go forward an hour for British Summer Time (BST). The scripts running on the server then update the web application at what appears to be 5pm for the users, instead of 4pm.

Is there a way to conditionally adjust the crontab's scheduled times for this time zone change?


The intention below is to run on the first day of every month at 00:00. During BST, my understanding is that this will run at 01:00 BST during daylight savings:

# m  h dom mon dow   user   command
  0  0   1   *   *   root   cd / && run-parts --report /etc/cron.monthly

What options do I have to ensure this always runs at 00:00 during both GMT and BST?

Server Timezone Info

$ timedatectl
               Local time: Mon 2021-11-01 22:57:41 UTC
           Universal time: Mon 2021-11-01 22:57:41 UTC
                 RTC time: Mon 2021-11-01 22:57:41
                Time zone: Etc/UTC (UTC, +0000)
System clock synchronized: yes
              NTP service: n/a
          RTC in local TZ: no
over 4 years ago · Santiago Trujillo
2 answers
Answer question

0

Wait one hour if your are in GMT:

0 23 0 * * root [ "$(date +'%Z')" == "GMT" ] && sleep 1h; cd / && run-parts --report /etc/cron.monthly
over 4 years ago · Santiago Trujillo Report

0

In my comments above, I praised Cyrus's reply, which I thought sounded very promising. Apparently, he disagreed, and deleted his response. Oh well...

This might be a good alternative for you:

https://www.the-art-of-web.com/system/cron-set-timezone/

If you are in a different time zone to some of your clients, or have a server that uses UTC to avoid daylight saving changes, it can be tricky to set a CRON script running at the correct time in a different time zone. Here we explore a couple of solutions. ...

[You can] specify a time zone for CRON:

# m h  dom mon dow   command
TZ=Australia/Sydney
0 0 * * * www-data /usr/bin/php $CRONSCRIPT

Unfortunately, setting the time zone here has no effect on when the CRON script is triggered. What it does instead is set an environment variable inside the shell in which the script is called. The script itself may then use the TZ time zone...

# m h  dom mon dow   command

SHELL=/bin/bash
TZ=Australia/Sydney
0 * * * * www-data [ "$(date +\%H\%M)" == "0000" ] && /usr/bin/php $CRONSCRIPT

Success! We now have a means of triggering a script at midnight in any time zone. The CRON command will be triggered every hour, but only continue to running the PHP script if it's midnight in the target time zone.

Just substitute your task for "php", and you should be good to go!

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!