Archive for February, 2008

Why I still use Perl..

22.02.2008 21:30

posted by: Benjamin Smith

Posted Under: ,

I have a sizable nagios log file that I needed to parse somewhat quickly to return the most recent iteration of a particular message. I thought about implementing something in python, but I whipped up the below Perl script in about few minutes that does just what I need...

#!/usr/bin/perl -w
use strict;
use Tie::File;
use Fcntl;

# Log file to parse.
my $logfile = '/var/log/nagios/syslog-nagios';
my @msgs = ();
# Get the logfile in a data structure quietly
tie @msgs, 'Tie::File', $logfile,mode => O_RDONLY or die "Cannot access $logfile: $!
";

# Loop through reverse sorted list of messages.
foreach my $line (reverse(@msgs)) {
    # print out the matched line..
    print ((split(':',$line))[6]) && last if ($line =~ /TRAFFIC-INTERNET/);
}

I'm sure I could have done some fancy map() or grep() but the above does the job great, and does it quickly. So yeah, that's one of the reasons I still dig Perl.

2 comments | 0 pingbacks

Move complete, new house rocks!

19.02.2008 10:59

posted by: Benjamin Smith

Posted Under: , ,

So we got all moved in this week and couldn't be happier. This was seriously bad timing on our part because of Valentines day and how busy I get a work due to this wretched holiday, but it all went smooth; only one broken bone :)

Check out the pictures:

New House

0 comments | 0 pingbacks

jQuery rocks.

13.02.2008 18:54

posted by: Benjamin Smith

Posted Under: , ,

So I had a simple task that I wanted done with minimal code. I wanted to basically update the copy of dynamically generated images every few minutes. So, within a function that gets called every minute I wrote this:

    $('img').each(
        function() {
            $(this).attr('src',$(this).attr('src'));
        }
    );

So easy, it should be illegal..

0 comments | 0 pingbacks
Previous month Next month