Amass

Using Perl and Logrotate to update stats and logs

March 26th, 2008 Luke

I recently moved girasquid.com, and all of my other sites, to my own Linux server - which I built myself.

It’s been a learning experience.

One of the things that I’ve been learning about is awstats, which is my stats utility of choice. In order to keep my log files from becoming too large, I’ve also turned on logrotate, so that it runs at 3:30 AM every day.

The only problem with this is that I’m running using virtualhosts - which means that I either need to create awstats configuration files for each specific virtualhost, and I need to create logrotate rules for each virtualhost’s log files.

They’re all in the same location, though. So I thought to myself: “hey! Why not get Perl to handle updating awstats for me? Then I can just write one logrotate rule for all of my virtualhosts!”. And so I did. This is what the logrotate rule looks like:

/home/*/logs/*.log { notifempty daily rotate 7 compress sharedscripts prerotate /usr/share/utils/updatestats.pl endscript postrotate /etc/init.d/apache2 reload endscript }

Which will nicely rotate both the access.log and error.log files for me(I haven’t quite worked out how to do per-virtualhost FTP logging just yet). The code inside /usr/share/utils/updatestats.pl is:

#!/usr/bin/perl -w use strict; opendir(SITES,'/etc/apache2/sites-enabled'); while(defined(my $site = readdir(SITES))) { next if $site =~ /^\.\.?$/; system("/usr/lib/cgi-bin/awstats.pl -update -config=$site"); } closedir(SITES);

As you can see, I basically loop through all of the currently enabled virtualhosts, and pass their names to awstats so that it will update them. This does require that your virtualhosts be named the same thing in either case(for example, the Apache virtualhost for this site is girasquid.com, and the awstats virtualhost is also girasquid.com), but as long as that’s true then it all works beautifully.

Do you like puzzles?

March 17th, 2008 Luke

Do you like puzzles? My girlfriend does.

She turned 19 on saturday, March the 8th - so I built her a puzzle for her birthday.

It’s called Puzzelation, and you can check it out at http://puzzelation.com.

Loading(and then scaling) an image using AS 2.0

March 3rd, 2008 Luke

Have you ever struggled with first loading in, and then scaling an image using ActionScript 2.0?

Loading and scaling images using ActionScript used to be the one thing in Flash that I struggled most with - I just couldn’t seem to find a nice way to get it done. But as it turns out, it’s already been done for me - the MovieClipLoader class exists for exactly the kind of voodoo I need:

var handler:Object = new Object(); handler.onLoadInit = function(mc:MovieClip) { if(mc._width != 200) { mc._width = 200; } if(mc._height != 200) { mc._height = 200; } } var target:MovieClip = createEmptyMovieClip("target",getNextHighestDepth()); var loader:MovieClipLoader = new MovieClipLoader(); loader.addListener(handler); loader.loadClip("my/image/path.jpg",target);

That code, when executed, will load the image at path my/image/path.jpg into the new movie clip we created, and then scale it to 200×200.