Re: first steps with perl, a log reader

From: Guardian Angel (the_guard_at_gmx.net)
Date: 11/16/03


To: Rob Dixon <rob@dixon.port995.com>
Date: 16 Nov 2003 20:45:12 +0100

On Sun, 2003-11-16 at 16:52, Rob Dixon wrote:
> Hi Sander. First of all, I guess this will feel like I'm ripping
> your code apart. Try to imagine me as your best-friend
> cardboard-cutout programmer with nothing but your interests
> at heart. :)

I'll do my best to see you as my best-friend, while you strip my 1st
code ;)
But thanx (also to the pther ppl) for pointing me to some things.

> Few people know what to make of Perl the first time they see
> it. People try to force it into either C or shell, but it's
> neither. Take a look at what I've written below, and keep an
> open mind!
>
It's hard to start (as always), but it will work...some day :)
I have some knowledge about the shell and linux, but i don't write code
in any other language, so it's all new to me.

>
> use strict; # Always
> use warnings; # Usually (same as -w qualifier but portable)

i will do that, "use warnings;" gave me more (human readable) errors, so
better to understand for me.

I was looking for the > and < operators. I had used them with backticks
(but gave a error message, because it was a "greater then" value,
because i left spaces like print $a > $b instead of print $a>$b ....
But now... i want to be more precise with my script.
So i made 2 extra if loops, 1 is looking for errors, and if so, also
check if there is no 127.0.0.x adres in it anymore (works so far :D)
then i want to sort the ip's ....and that's what dazzling me now...
This is what i want: I Look in the (newly) written error.log, and see
immediatley that someone with ip 123.45.6.7 has tried 1x to login. But
123.45.6.8 has tried to login 50x in the last 6 days...
Now my thought was that i made an array to put everything from while
<ER>, and when it's an error message and *not* 127.0.0.x in the array,
then sort, and put it in the error.log.... unfortunatly it's not
working.... so i looked for the subroutines in Learning Perl... but i
don't get it *how* you can get these values....
                
Thanx a lot

Sander

#!/usr/bin/perl
use strict;
use warnings;
open (ER, "</home/unicorn/Plscripts/error_log") || die "can't open ER,
$!\n"; #opening error_log for ReadNow all the advice helped me out,
open (EL, ">>/home/unicorn/Plscripts/error.log") || die "can't open EL,
$!\n"; #opening ERROR.LOG for Write

while (<ER>) { #as long as ER is open, read....
       if (/error/) { #if there is any errormessage in the file
                       if (!/127.0.0.*/) { #and it's not local 127.0.0.x
                @sorted_list = sort by_ip (ER) ; #the inputfile is sorted by ip in
@sorted_list
                print EL $_; #print output to ERROR.LOG #was print EL $_;
                }
        }
}
#sub by_ip {
# @sorted_list = sort { $a <=> $b } EL;
# }



Relevant Pages

  • Re: memory problem, I guess
    ... If I use part of the data I'm getting the right transform. ... I searched the web and found that the error message is ... Below is the error message I'm getting when I increas my array size: ... trying to use (it would have been good to specify that)? ...
    (comp.lang.fortran)
  • Re: UDT Array Parameter
    ... It looks like the array passing was already working - it appears that my ... same error message; apparently, the late-bound function is the IsArray ... Private Sub Form_Load ... Dim testAs myTestType, b As Boolean ...
    (microsoft.public.vb.general.discussion)
  • Re: "Flex memory error" woes
    ... as the error message is not very helpful and the program ... which kept all allocated block pointers in an array and before ... NB I do let allocated arrays hold pointers - it seems to work although I ...
    (comp.sys.acorn.programmer)
  • Re: [RFC] [PATCH] 32-bit pointers in x86-64
    ... I continue to think that the error message 'initializer element ... extern char array; ... is incorrect - the compiler generally has no knowledge what 'array' is (it may ... sure I have an open bug for this, but the sad thing is that bugs like this ...
    (Linux-Kernel)
  • Re: Problem opening documents in 2003
    ... Terry Farrell - MS Word MVP ... opening but this time without displaying the error message. ...
    (microsoft.public.word.application.errors)