#!/bin/csh #Birds-Eye.Net UNIX Daylight Savings Time Adjustment ScriptBack to Birds-Eye.Net Script Archive
# ##<PRE> ######################### DO NOT REMOVE THIS HEADER ################################# # # # Birds-Eye Network Services, LLC # # Birds-Eye.Net's UNIX Daylight Savings Time Adjustment Script # # bens_dst.csh # # # # This c-shell script can be used to automatically adjust the time of a UNIX server # # so that it correctly observes daylight savings time (DST). # # # # By: Bruce Bahlmann # # (C) Copyright, Birds-Eye Network Services, LLC, ALL RIGHTS RESERVED # # # # NOTICE: All use of the software (in whole or in part) is restricted. Any sale, # # marketing, distribution, or transfer of software copies, associated data, source # # code, information (including manuals), configuration files, or licenses are # # restricted. Internal use of this software requires a license and/or express # # written permission from Birds-Eye Network Services, LLC. Any other use of this # # software is restricted. This software is not sold as part of an enterprise # # license and thus is restricted as such. # # # # To purchase access rights to this software contact: # # Birds-Eye.Net, LLC # # info[_at_]birds-eye.net # # OR go to www.birds-eye.net/consulting to obtain a license # # # ######################### DO NOT REMOVE THIS HEADER ################################# # Generic Daylight Savings Time script # Created: 08/23/2000 # Version: 01.01 10/22/2000 bbahlmann Only add/removes DST (region independent) # Version: 01.00 08/23/2000 bbahlmann initial release # # dst.csh automatically changes the timezone in accordance with Daylight # Savings Time. This script will make the correct edit to /etc/TIMEZONE to # begin or end DST observance. This script can also be run from the command # line. # # TODO: # Unfortunitely, this dst.csh currently requires a reboot to apply changes # (on the server) after this change. This could be easily added to the script # but may not be desirable... Need to find a better way to apply this change # across all running applications. # ### INSTRUCTIONS: ############################################################# # # Set system specific information below and then make the suggested CRON entry as # below. Note, that depending on where you live, the /etc/TIMEZONE entry for TZ must # be set correctly for which TIMEZONE you live in (e.g. central-USA --> TZ=CST6). If # the TIMEZONE is set incorrectly this DST script will adversely change your time. # # [cron entry] # * * * * * /etc/dst.csh > /dev/null 2>&1 # ## system/location specific set tzfile = "/etc/TIMEZONE" ## path to TIMEZONE file set loc = "USA" ## supported locations: USA, EEC ## Note ECC is for most contries in western europe #### END OF EDITABLE CONFIGURATIONS ########################################### ## read in date particulars set wd = `date +%w` ## Day of week 0-7 where 0=Sunday set day = `date +%d` ## Day of month 01-31 set mon = `date +%m` ## Month of year 01-12 set hr = `date +%H` ## Hour 00-23 set min = `date +%M` ## Minute 00-59 if ($wd != 0) then echo "Invalid day for DST change [Sundays only] -- aborting" exit(-1) ## Only proceed between the hour of 1:55 AM and 1:59 AM -- otherwise abort else if (($hr != 01) || ($min <= 54)) then echo "Hr [$hr] Min [$min] incorrect must be 1:55-59 -- aborting" ## A sunday on days 01-07 would represent the FIRST sunday of a given month ## A sunday on days 25-31 would represent the LAST sunday of a given month (of 31 days) else if ($loc == "USA") then ## run only in April (04) and October (10) if ($mon == 04) then ## determine if it is the first SUNDAY of month if ((01 <= $day) && ($day <= 07)) then ## begin DST set tz = `grep ^TZ= $tzfile` set dst_less_tz = `echo $tz|sed s/DST//` if ($tz == $dst_less_tz) then ## TZ does not contain trailing DST string -- backup and add it to start DST cp $tzfile $tzfile\.old sed s/^$tz/$tz\DST/ $tzfile > $tzfile\.new cp $tzfile\.new $tzfile set ntz = `grep '^TZ=' $tzfile` echo "TZ changed from [$tz] to [$ntz] -- now observing DST" else echo "DST already set [$tz] -- aborting" endif else echo "Not first SUNDAY in APRIL -- cannot change DST" endif else if ($mon == 10) then ## determine if it is the first SUNDAY of month if ((25 <= $day) && ($day <= 31)) then ## end DST set tz = `grep '^TZ=' $tzfile` set dst_less_tz = `echo $tz|sed s/DST//` if ($tz != $dst_less_tz) then ## TZ contains trailing DST string -- backup and remove it to end DST cp $tzfile $tzfile\.old sed s/^$tz/$dst_less_tz/ $tzfile > $tzfile\.new cp $tzfile\.new $tzfile set ntz = `grep '^TZ=' $tzfile` echo "TZ changed from [$tz] to [$ntz] -- no longer observing DST" else echo "DST already removed [$tz] -- aborting" endif else echo "Not last SUNDAY in OCTOBER -- cannot change off DST" endif else echo "Not a valid month [$mon] to change DST" endif else if ($loc == "EEC") then ## run only in March (03) and October (10) if ($mon == 03) then ## determine if it is the first SUNDAY of month if ((25 <= $day) && ($day <= 31)) then ## begin DST set tz = `grep ^TZ= $tzfile` set dst_less_tz = `echo $tz|sed s/DST//` if ($tz == $dst_less_tz) then ## TZ does not contain trailing DST string -- backup and add it cp $tzfile $tzfile\.old sed s/^$tz/$tz\DST/ $tzfile > $tzfile\.new cp $tzfile\.new $tzfile set ntz = `grep '^TZ=' $tzfile` echo "TZ changed from [$tz] to [$ntz] -- now observing DST" else echo "DST already set [$tz] -- aborting" endif else echo "Not last SUNDAY in MARCH -- cannot change DST" endif else if ($mon == 10) then ## determine if it is the first SUNDAY of month if (25 >= $day <= 31) then ## end DST set tz = `grep ^TZ= $tzfile` set dst_less_tz = `echo $tz|sed s/DST//` if ($tz != $dst_less_tz) then ## TZ contains trailing DST string -- backup and remove it cp $tzfile $tzfile\.old sed s/^$tz/$dst_less_tz/ $tzfile > $tzfile\.new cp $tzfile\.new $tzfile set ntz = `grep '^TZ=' $tzfile` echo "TZ changed from [$tz] to [$ntz] -- no longer observing DST" else echo "DST already removed [$tz] -- aborting" endif else echo "Not last SUNDAY in OCTOBER -- cannot change DST" endif else echo "Not a valid month [$mon] to change DST" endif else echo "Location [$loc] is unsupported -- check $0 configurations" exit(-1) endif