Visit Our UNIX and Linux User Community


Perl log parcer. (for custom logs details inside)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Perl log parcer. (for custom logs details inside)
# 1  
Old 08-30-2002
Perl log parcer. (for custom logs details inside)

OS:sol8

ok 2 things are very important. I will give examples of the logs and the client file for testing.

Object: to display on the web sometime to parse your custom logs basied on the inputed date and client selected.

I know alot of ppl are like who care. but i saw a perl script on here that gave me an idea on how do to this. so thanks auswipe for the logic. this is how i was able to turn something i saw into something i can use.

CLIENT LIST
Code:
[hostname]optimus_P$cat /var/adm/scripts/client_list
A000
A111
A222
#A333
A444

LOG FILE
logname = 20020830.ncftp_in.log
Code:
CLIENT: A111     TIME: 20:25:00
file1
file2

CLIENT: A222     TIME: 20:25:00
file1

CLIENT: A111     TIME: 20:30:00
file3
file4
file5

CLIENT: A333     TIME: 20:30:01
file1
file2

CLIENT: A444     TIME: 20:35:00
file1
file2

CLIENT: A111     TIME: 20:35:00

The script:
Code:
#!/usr/bin/perl -w

use CGI qw(:standard);

$PTITLE="Inbound and Outbound Log Checker";

print header, start_html($PTITLE), h2($PTITLE), hr;

$CLIENTFILE="/var/adm/scripts/client_list";

open(CLIENTFILE, "$CLIENTFILE") || bail ("$CLIENTFILE: \($!\)");
foreach (<CLIENTFILE>) {
        chomp;
        push(@client_list,$_) if ( $_ =~ /^\w/);
};


print start_form();
        print ("What client do you want to see? ",popup_menu("client_code", \@client_list)) ;
        print br(sup("note: DMZ files are NOT SHOWEN on the INBOUND side"));
        print p("Inbound or Outbound log? ",radio_group("in_out", ["in","out"]));
        print ("Enter a logdate",textfield(
                -NAME => "date",
                -DEFAULT => `date +%Y%m%d`,
                -OVERRIDE => 0,
                -SIZE => 7));
        print br(sup("ex. 20020131 = year 2002/month 01/day 31"));
        print p(submit("search"), reset("clear"));
print end_form(),hr();

if (param()) {
        print (h2("Current Time: ", `date`, hr));
        $date=param("date");
        $in_out=param("in_out");
        $LOGFILE="/homes/log/${date}.ncftp_${ in_out }.log";
        open(LOGFILE, "$LOGFILE") || bail ("$LOGFILE: \($!\)");
        foreach (<LOGFILE>) {
                chomp;
                push(@lines,$_);
        };

        $client=param("client_code");
        for ($i = 0; $i <= $#lines; $i++) {

                if (($lines[$i] =~ m/CLIENT\: $client/i) && ($lines[$i+1] =~ /\S/)) {
                        print br;

                        while ($lines[$i] =~ /\S/) {
                                print ("$lines[$i]");
                                print br;
                                $i++;
                        };
                };
        };
};

print end_html;

sub bail {
        $error="@_";
        print h1("Unexpected Error"), p($error), end_html;
        die $error;
}

# 2  
Old 08-30-2002
Re: Perl log parcer. (for custom logs details inside)

Quote:
Originally posted by Optimus_P
I know alot of ppl are like who care. but i saw a perl script on here that gave me an idea on how do to this. so thanks auswipe for the logic. this is how i was able to turn something i saw into something i can use.
Smilie Glad that my code could have been of some assistance. Smilie

That Perl is purt near good for ripping apart log files, eh?

Previous Thread | Next Thread
Test Your Knowledge in Computers #865
Difficulty: Easy
The original idea of a member badging system at UNIX.com was first proposed by Ravinder Singh in 2018.
True or False?

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

2. Shell Programming and Scripting

Script to append user details as soon as he logs in

I'm wishing to create a log myself where I wish to: 1.Write a script in /bin folder to make a separate log in var/log folder & 2.Call the script in bashrc each time a user logs in, I'm trying to avoid CRONJOB as it would take too much of my memory after iterations. So I just need to append the... (2 Replies)
Discussion started by: Lionking93
2 Replies

3. Web Development

Apache/2.2.15 custom error log

Hello, I've updated my apache access log to include the x-forward-for IP instead of my client(loadbalancer) ip. However, i can't seem to find a way to do the same for the error logs. Can someone please assist. Thank you. -K (0 Replies)
Discussion started by: kmaq7621
0 Replies

4. Windows & DOS: Issues & Discussions

how to install custom .bat files in perl

I'm using damke to install perl modules on windows. I have my custom .bat files for the perl script. How to overwrite the .bat files that gets generated by pl2bat with my custom .bat files! Thanks, Hansini (1 Reply)
Discussion started by: hansini
1 Replies

5. Shell Programming and Scripting

win32 ole in deepr details in perl

Hello Gurus, I am begginer in perl. I would like to ask several questions, some related to perl and its syntax but most will be regarding to WIN32 OLE. My main goal is to develop script that will check word document structure (return some information) and make some changes in this document (if it... (0 Replies)
Discussion started by: wakatana
0 Replies

6. Shell Programming and Scripting

How can I do one liner import multiple custom .pm files in my perl script?

I am new for Perl I want to ask one question. I have around 50 custom packages which i am using in my Perl script. I want to import all .pm packages in my Perl script in an easy way. Right now i have to import each package individually. So Is there any way to do so?? Right Now i am doing like: ... (1 Reply)
Discussion started by: Navrattan Bansa
1 Replies

7. Red Hat

Need to mount LUN on two linux boxs (one rw the other ro) caveat details inside

Calling all Linux GURU's. The purpose of this thread is to try an recreate what we already have stood up in my environment, however the steps i am having to produce my own. I have got multiple applications that dump the data to various LUNs, the LUNs are managed by an Enterprise SAN... (11 Replies)
Discussion started by: jcejka
11 Replies

8. UNIX for Dummies Questions & Answers

at -l doesnt give details of the scheduled job. How to get the details?

I have scheduled couple of shell scripts to run using 'at' command. The o/p of at -l is: $ at -l 1320904800.a Thu Nov 10 01:00:00 2011 1320894000.a Wed Nov 9 22:00:00 2011 1320876000.a Wed Nov 9 17:00:00 2011 $ uname -a SunOS dc2prcrptetl2 5.9 Generic_122300-54 sun4u sparc... (2 Replies)
Discussion started by: superparticle
2 Replies

9. Shell Programming and Scripting

PERL String to Date (Custom format yyyymmdd to dd-mon-yyyy)

Hi All, I am learning PERL for one of the projects, and in one of these scripts, I read a flat text file and print in the terminal. The problem is, the text file has a date field. The format is yyyymmdd. I need to display this as dd-mon-yyyy. Any ideas to do this? Thanks a lot for the... (9 Replies)
Discussion started by: guruparan18
9 Replies

10. Shell Programming and Scripting

Replace aword in a.The replaced word should not be overwitten in perl(details inside)

Hi i am trying to write a perl program where i have to open a 1)directory "unit" 2) rename the files in the dir say file1.txt;file2.txt...file5.txt to file1_a.txt;file2_a.txt,....file5_a.txt ;file1_x.txt ;file2_x.txt 3) open these renamed files and replace the words lets say file1_a.txt... (7 Replies)
Discussion started by: madhul2002
7 Replies

Featured Tech Videos