djbdns dnscache log converter

I’ve just had to struggle with the hex ip addresses which dnscache logs, after a bit of searching I found some nice notes about the log format here thanks to Rob Mayoff.

Finally I found this handy perl script.

Perl goodies

Found these two nice links this morning, first a very nice periodic table of perl operators and second, a useful little cgi that helps find out what is installed on your server.

Perl timeouts

Some perl that sets a timeout value


$SIG{ALRM} = sub { alarmed(); };

eval { check_whatever; };

sub check_whatever()
  # stuff to do that might timeout
  exit 0;

sub alarmed()
  # stuff to do after the alarm has gone off.
  exit 1;

Thanks to Timbo for help with this…

URL Regex

Justin sent over a regex he wrote for catching the various bits of a url:


Parsing ftp xferlogs

I need to parse ftp xferlogs and our current regex was broken by spaces in uploaded filenames. Have fixed it, is shown below with the names of the fields.

        $_ =~ /^(\w{3} \w{3} \s?\d\d? \d\d:\d\d:\d\d \d{4})
                (\d\d?)(\S+) (\d+) (.+) ([ab]) (_|C|U|T) (i|o)
                (a|g|r) (\w+) (\w+) (0|1) (\w+|\*) ([c|i])$/o;

        $current_time = $1;
        $transfer_time = $2;
        $remote_host = $3;
        $byte_count = $4;
        $filename = $5;
        $transfer_type = $6;
        $special_action_flag = $7;
        $direction = $8;
        $access_mode = $9;
        $username = $10;
        $service_name =$11;
        $authentication_method = $12;
        $completion_status = $14;

Perl CPAN reconfiguration

To reconfigure CPAN:

towel root # perl -MCPAN -e shell

cpan shell -- CPAN exploration and modules installation (v1.59_54)
ReadLine support available (try 'install Bundle::CPAN')

cpan> o conf init

/usr/lib/perl5/5.6.1/CPAN/ initialized.

CPAN is the world-wide archive of perl resources. It consists of about
100 sites that all replicate the same contents all around the globe.
Many countries have at least one CPAN site already. The resources
found on CPAN are easily accessible with the module. If you
want to use, you have to configure it properly.

If you do not want to enter a dialog now, you can answer 'no' to this
question and I'll try to autoconfigure. (Note: you can revisit this
dialog anytime later by typing 'o conf init' at the cpan prompt.)

Are you ready for manual configuration? [yes]