Skip to main content
Home
The Baheyeldin Dynasty
The journey for wisdom starts with knowledge
  • Home
  • About
  • Site Map
  • Contact

How To Run A Script When Daylight Savings Change

  1. Home

By Khalid on 2026/03/14 - 16:58, last updated 2026/03/14 - 17:05

If you are living in a place where daylight savings come into effect in spring, and goes back to standard time in autumn, then you are probably familiar with a few things that you need to do twice a year. These include things like adjusting the clock on your range/stove, or old clocks.

But that could also include things like restarting a program that does not handle timezone changes automatically.

Whatever the case may be, here is a script that allows you to run some of these repetitive tasks, or at a minimum, email you a list of things you need to change manually.

The trick is to detect timezone change from yesterday to today.

Copy the code below, and place it somewhere, e.g. /usr/local/bin/dst-change.sh.

TMP_BODY="/tmp/dst-change.txt"
# Change this host name
HA_HOST="hass"
# Change your email address
EMAIL="foo@example.com"

# Check if timezone offset has changed
TZ_CURR=`date +%Z`
TZ_YESTERDAY=`date -d 'yesterday' +%Z`

# Check if timezones are the same yesterday and today
if [ "$TZ_CURR" = "$TZ_YESTERDAY" ]; then
  # Daylight savings has not changed, nothing to do
  exit
fi

# Everything below this line is executed when a daylight savings change
# is detected

# Restart appdaemon on HomeAssistant
ssh $HA_HOST 'sudo systemctl restart appdaemon'

# Create the text of the email
cat > $TMP_BODY <<-EOF
Please adjust the clock on the following:
1. Stove
2. Water softener
3. ...

EOF

# Mail it
mail -s "DST change" $EMAIL < $TMP_BODY

# Cleanup
rm -f $TMP_BODY

Make sure you make it executable:

chmod +x /usr/local/bin/dst-change.sh

Then in crontab, add the following, and adjust it to when your location switches every year.
In my case, the Eastern Daylight Savings to Eastern Standard Time happens in March and November on a Sunday. So I run the script on every Sunday of those months. Only when a change is detected would the commands run, and the email is sent.

# Check if daylight savings changed, and send a reminder
5 3 * 3  Sun /usr/local/bin/dst-clock-change.sh
5 1 * 11 Sun /usr/local/bin/dst-clock-change.sh
Contents: 
Linux
  • Add comment

Current

Talks

  • Presentations and Talks

Search

Site map

Contents

  • Family
    • Khalid
    • Ancestry
    • Extended
  • Friends
  • Nokat نكت
  • Writings
    • Cooking
    • Culture
    • Science
    • History
    • Linguistics
    • Media
    • Literature
    • Politics
    • Humor
    • Terrorism
    • Business
    • Philosophy
    • Religion
    • Children
  • Technology
    • Linux
    • Arabization
    • Drupal
      • Association
    • Software
    • Internet
    • Technology in Society
    • Digital Archeology
    • NCR History
    • MidEast Internet
    • Programming
    • Saudi ISPs
    • Miscellaneous
  • Places
    • Canada
      • Weather
    • Egypt
      • Cuisine
      • Alexandria
      • E.G.C.
    • USA
    • Saudi Arabia
  • Interests
    • Astronomy
    • Fishing
    • Photography
    • Snorkeling
    • Nature
    • Photomicroscopy
  • Miscellany

In Depth

  • al-Hakim bi Amr Allah: Fatimid Caliph of Egypt الحاكم بأمر الله
  • Alexandria, Egypt
  • Arabic on the Internet
  • Articles on the history of Muslims and Arabs in the Iberian Peninsula تاريخ المسلمين و العرب في الأند
  • DIY GOTO Telescope Controller With Autoguiding and Periodic Error Correction
  • E.G.C. English Girls College in Alexandria, Egypt
  • Egyptian Cuisine, Food and Recipes مأكولات مصرية
  • George Saliba: Seeking the Origins of Modern Science?
  • Internet Scams and Fraud
  • Mistaken for an Arab or Muslim: Absurdities of being a victim in the War on Terror
  • Mistaken Identity: How some people confuse my site for others
  • One People's Terrorist Is Another People's Freedom Fighter
  • Overview of Google's Technologies
  • Photomicroscopy
  • Pseudoscience: Lots of it around ...
  • Resources for using Google Adsense with Drupal
  • Rockwood Conservation Area, Southern Ontario
  • Selected Symbolic Novels And Movies
  • Snorkeling the Red Sea near Jeddah
  • Updates and Thoughts on the Egyptian Revolution of 2011

Recent Content

Most recent articles on the site.

  • How To Run A Script When Daylight Savings Change
  • Moon Sighting Is Obsolete: Lunar Month Starts Should Be By Astronomical Conjunction
  • Presentations and Talks
  • How To Suppress Excessive Logging by PAM
  • L.G. Alexander: Operation Mastermind
more

Most Comments

Most commented on articles ...

  • Another scam via Craigslist: offering more than asking price
  • Warning to female tourists thinking of marrying Egyptians
  • Craigslist classified for used car: Cheque fraud scam
  • Winning the lottery scam email: World Cup South African lottery
  • Email Scam: BMW 5 Series car and lottery winning
more

About Khalid

Various little bits of information ...

  • Khalid Baheyeldin: brief biography
  • Presentations and Talks
  • Youtube Videos
  • GitHub Projects
  • Drupal.org Profile
  • Astrophotography @ Flickr

Sponsored Links

Your Link Ad Here

Tags

419 Android App Arabic backup Balkanization Comet Conspiracy Coronavirus COVID-19 CPU DIY Ericsson Firefox GSM Home Assistant Kubuntu Laptop Mobile OnStep OpenWRT Python Rogers Router Scam Sony Spectrum tablet Telescope Ubuntu
More

© Copyright 1999-2026 The Baheyeldin Dynasty. All rights reserved.
You can use our content under the Terms of Use.
Please read our privacy policy before you post any information on this site.
All posted articles and comments are copyright by their owner, and reflect their own views and opinions, which may not necessarily be consistent with the views and opinions of the owners of The Baheyeldin Dynasty.

Web site developed by 2bits.com Inc.