U.S. Daylight Savings update test for Linux

For those of you running Linux or Solaris, here's a Perl script I found that will verify that your system is properly updated for the Daylight Savings changes in the U.S. for this year:


#!/usr/bin/perl

###
### The following sript will check if the system has the correct defination
### for Daylight Saving Time. The start of Daylight saving time has changed
### to the second Sunday in March starting in 2007.
###
### The script displays the time before and after the switch to Daylight
### saving time. The Time zone name should change, for example CDT to CST.
### The script has been tested on Solaris, Red Hat and AIX.
###
### Original posted on:
### http://blight.ca/twiki/bin/view/Notes/CheckDaylightSaving
###

use POSIX qw/mktime strftime/;

$before = mktime( 59, 59, 1, 11, 2, 107 );
$after = $before + 1;

$s_before = localtime( $before );
$s_after = localtime( $after );
$zone_before = strftime "%Z", localtime( $before );
$zone_after = strftime "%Z", localtime( $after );

if( $ARGV[0] =~ /-v/ ) {
print "\nTest if new timezone definitions are current for standard and\n";
print "daylight saving. Starting in 2007 it should switch on second\n";
print "Sunday in March, not April in most locations in North America\n\n";
print "$s_before $zone_before and 1 second later its $s_after $zone_after\n\n";

$os = `uname -s`; chop( $os );
if( $os eq "SunOS" ) {
$x = `echo \$TZ`;
print "local TZ environment variable: $x\n";
system( "ls -al /etc/TIMEZONE" );
system( "ls -al /etc/default/init" );
system( "cat /etc/default/init" );
}
elsif( $os eq "Linux" ) {
system( "ls -al /etc/sysconfig/clock" );
system( "cat /etc/sysconfig/clock" );
}
elsif( $os eq "AIX" ) {
$x = `echo \$TZ`;
print "local TZ environment variable: $x\n";
system( "ls -al ls /etc/environment" );
system( "grep \"TZ=\" /etc/environment" );
}
print "\n";
}

### Output
print "\n\n\n\n\n";

if ( $zone_before ne $zone_after ) {
print "timezones standard/daylight saving time test out okay\n";
} else {
print "**** Error ****** \n";
print "TimeZone standard/daylight saving time doesn't test out okay\n";
}

##############################################################################
### This script is submitted to BigAdmin by a user of the BigAdmin community.
### Sun Microsystems, Inc. is not responsible for the
### contents or the code enclosed.
###
###
### Copyright 2007 Sun Microsystems, Inc. ALL RIGHTS RESERVED
### Use of this software is authorized pursuant to the
### terms of the license found at
### http://www.sun.com/bigadmin/common/berkeley_license.html
##############################################################################

Copy and paste this code into a file, make it executable, then simply run it (Optionally. supply the -v flag for a verbose output). If you'd rather, I also attached this in a file that can be downloaded.

My laptop passes running Ubuntu Edgy 6.10. I'll have to check out my other Linux systems, too.

AttachmentSize
test_dst.txt2.38 KB