perl

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

#!/usr/bin/perl

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

alarm(20);
eval { check_whatever; };
alarm(0);

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:

(http|ftp):\/\/((?:[^./]+\.){1,}(?:[^./]+))((?:/[^/]+)*/)([^/]+)\.([^./]+)

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;
        $authenticated_user_id=$13;
        $completion_status = $14;