Saturday, February 20, 2010

Daylight Savings Time and Scheduling Jobs

Twice a year, we move our clocks around and either "gain" or "lose" an hour. This "Daylight Savings" can cause issues with scheduled jobs because an hour is either missed or repeated.

In the U.S.A., we "spring forward" on the second Sunday in March and skip the 0200 hour; our clocks go from 0159 to 0300 and any jobs we had scheduled between that time DO NOT HAPPEN.

Can I emphasize that again? If you scheduled something for 2AM, like your backups, it DOES NOT HAPPEN.

Then, we "fall back" on the first Sunday in November and repeat the 0100 hour; our clocks go from 0159 to 0100 and any jobs we had scheduled between that time HAPPEN TWICE.

This just sucks all around, doesn't it?

What's an admin to do about it? Well, you can avoid scheduling jobs from 0100 to 0300, you can schedule the jobs and move jobs as needed when Daylight Savings Time approaches or you can avoid the problem entirely by running your systems on UTC.

As soon as I get a job where I can run all of my systems in UTC, I'll let you know.

Daylight Savings sucks.

Labels: , , ,

Tuesday, January 26, 2010

Rotating log files without parsing ls

When people are rotating custom log files, they often parse ls because, well, because they don't know any better.

Now you will and you can smack them appropriately.

If you have a bunch of log files with sequential file names (like dates), then you can easily trim to a specific number of files to keep.
$ echo mylog.*.gz
mylog.20100126.gz
mylog.20100125.gz
mylog.20100124.gz
mylog.20100123.gz
mylog.20100122.gz
mylog.20100121.gz
mylog.20100120.gz
mylog.20100119.gz
$ numsave=5
$ echo mylog.*.gz | tr " " "\012" | sort -nr | while read f
> do
> if [ ${numsave} -gt "0" ] ; then
> numsave=$((numsave - 1))
> else
> echo DELETE $f
> fi
> done
DELETE mylog.20100121.gz
DELETE mylog.20100120.gz
DELETE mylog.20100119.gz
And you can easily substitute an "rm" where I put "echo DELETE".

But what if you named the files like a moron such that you can't sort by name. Like, "26Jan2010", that kind of moron.
$ echo mylog.*.gz
mylog.26Jan2010.gz

mylog.25Jan2010.gz

mylog.24Jan2010.gz

mylog.23Jan2010.gz

mylog.22Jan2010.gz

mylog.21Jan2010.gz

mylog.20Jan2010.gz

mylog.19Jan2010.gz

$ numsave=5
$ ls -t1 mylog.*.gz | while read f
> do
> if [ ${numsave} -gt "0" ] ; then
> numsave=$((numsave - 1))
> else
> echo DELETE $f
> fi
> done
DELETE mylog.21Jan2010.gz
DELETE mylog.20Jan2010.gz
DELETE mylog.19Jan2010.gz

Labels: , , ,