CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Parse inconsistent log files

 



chadv99
New User

Jul 21, 2011, 8:54 AM

Post #1 of 3 (375 views)
Parse inconsistent log files Can't Post

I'm pretty new to perl and have not been able to find a solution searching this site or other. Hopefully somebody can give me a good start on my problem.

I have weekly log files from many linux nodes and want to parse each one and create somewhat of a summary report.

Example log file from one machine:

##################################################################
# Changes
##################################################################
Jul 12 06:52:22 node1 passwd: pam_unix: password changed for user
Jul 12 06:52:28 node1 passwd: pam_unix: password changed for user
##################################################################
# Records
##################################################################
Jul 12 06:51:35 node su: pam_unix: session opened for user root by user (uid=500)
Jul 12 06:51:37 node su: pam_unix: session closed for user root


I need to parse each file from each node and create a new file with a summary. Trying to grab everything below changes and put that in the summary file under changes. So, I would have every "changes" entry from each file under one "changes" heading in the summary file, etc. Any help or direction would be greatly appreciated. Thanks!


kwatts59
Novice

Jul 21, 2011, 11:32 AM

Post #2 of 3 (371 views)
Re: [chadv99] Parse inconsistent log files [In reply to] Can't Post

Write a PERL script to do the following
Open the summary file for writing,
Open the log file for reading,
Read each line of the log file and search for the word "Changes" using the index command,
If you get a hit, print the line in the summary file,
Keep reading and printing to the summary file until you find the word "Records"
Close files

If you have problems, post your script here so we can examine it.


BillKSmith
Veteran

Jul 21, 2011, 2:54 PM

Post #3 of 3 (362 views)
Re: [chadv99] Parse inconsistent log files [In reply to] Can't Post

Refer to perldoc perlop. See section on range operator in scalar context for a neat way to implement the testing part of kwats59's algorithm.
Good Luck,
Bill

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives