Operating System - HP-UX
1830620 Members
3019 Online
110015 Solutions
New Discussion

Daylight Savings Time Email

 
SOLVED
Go to solution
Robert Comber
Advisor

Daylight Savings Time Email

Hello Forumers,

I'm positive that I have seen a similar posting but I can't find it using search. I want to notify a list of users when the next time change will occur. I know the next time change in the US occurs on April 4th but I want an automatic method that would trigger whenever the time change is less than 14 days away. I want to run a cron every weekday and send emails to a list of users indicating when the time will change. The list will be handled by an alias so that part is easy.

I've looked at tztab but that looks like a lot of trouble to interpret. I know somebody wrote a script to do this!!

Thanks,
Bob
6 REPLIES 6
Dave La Mar
Honored Contributor

Re: Daylight Savings Time Email

In your cron'd script.

if [ `date +%d` -lt 31 ]
then
whatever
fi

Best regards,

dl
"I'm not dumb. I just have a command of thoroughly useless information."
Robert Comber
Advisor

Re: Daylight Savings Time Email

Thanks Dave but I don't think your method will work. All it does is determine if the current day of the month is less than 31. How does that help to determine the number of days until Daylight Savings Time goes in or out of effect?

Thanks,
Bob
A. Clay Stephenson
Acclaimed Contributor
Solution

Re: Daylight Savings Time Email

I think this Perl script will do what you need.

Let your cron script run every Mon-Fri and then add this logic (and make sure that PATH is set and exported):

TYPESET -i10 DAYS_LEFT=$(dst.pl -d -e)
if [[ ${DAYS_LEFT} -lt 14 ]]
then
echo "Time will change in ${DAYS_LEFT} days" > tmpfile
echo "Other Stuff you might want" >> tmpfile
dst.pl -n >> tmpfile # displays actual transition time/date
cat tmpfile | mail user1 user2
rm tmpfile
fi

You should add a better tmpfile name and note that Daylight Savings Time is tied to a particular TZ setting. If your environment spans multiple timezones then you need to take that into account.

e.g.

DAYS_LEFT=$(TZ=CST6CDT dst.pl -d -e)
that will set TZ to CST6CDT for just this command.

Here's the Perl script. Invoke as dst.pl -u for full usage.


If it ain't broke, I can fix that.
A. Clay Stephenson
Acclaimed Contributor

Re: Daylight Savings Time Email

One more note. This here script is only as good as that there the strftime() function. HP is rather good at handling time changes because it does have the configurable /usr/lib/tztab file. Most other flavors of UNIX require a libC patch when off-the-wall time change rules appear at the whim of a regulatory body BUT this does imply that you must keep your tztab current.
If it ain't broke, I can fix that.
Dave La Mar
Honored Contributor

Re: Daylight Savings Time Email

Sorry Bob, but I thought you were going to cron this a a set date in advance.
No points here thanks.

Best regards,

dl
"I'm not dumb. I just have a command of thoroughly useless information."
Robert Comber
Advisor

Re: Daylight Savings Time Email

As usual A. Clay's solution worked. Thanks to both of you for responding.

Bob