473,748 Members | 2,173 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Analyse Log file

2 New Member
Hello,
I am new on perl and want to do one script who will ask for the name of the log file to analyse and will give the statictics :
1- the covered period of the log (start-end) by date and hours;
2- the total number of lines (traces) foreach adress;
3-the total numbers of traces for each service;
4-the total number of connections pop, ssh and imap;
5- the list of addresses that made a ssh connection and how many for each
6- list of adresses that sent an email by sendmail and how many for each

example of log to ananyle :
Expand|Select|Wrap|Line Numbers
  1. Jan 13 04:05:43 client.IRO.UMontreal.CA sendmail[22674]: i0D95hr8022674: from=root, size=271, class=0, nrcpts=1,
  2. msgid=<200401130905.i0D95hr8022674@client.IRO.UMontreal.CA>,relay=root@localhost
  3. Jan 13 04:05:44 client.IRO.UMontreal.CA sendmail[22674]: i0D95hr8022674: to=root, ctladdr=root (0/1), delay=00:00:01,
  4. mailer=relay, pri=30271, relay=[127.0.0.1], dsn=2.0.0, stat=Sent (i0D95hEt022675 Message accepted for delivery)
  5. Jan 13 04:05:45 server.IRO.UMontreal.CA sendmail[22627]: i0D95jQ6022627: from=<root@gamma.IRO.umontreal.ca>,
  6. size=750, class=0, nrcpts=1,msgid=<200401130905.i0D95hr8022674@client.IRO.UMontreal.CA>,
  7. proto=ESMTP, daemon=MTA, relay=client.IRO.UMontreal.CA [132.204.24.102]
  8. Jan 13 04:08:20 server.IRO.UMontreal.CA sendmail[23390]: i0D98KQ6023390:<cpm2000@IRO.UMontreal.CA>...
  9. User unknown
  10. Jan 13 04:12:41 server.IRO.UMontreal.CA ipop3d[26735]: pop3 service init from 132.204.24.100
  11. Jan 13 04:12:41 server.IRO.UMontreal.CA ipop3d[26735]: Logout user=??? host=server.IRO.UMontreal.CA [132.204.24.100]
  12. Jan 13 04:12:42 server.IRO.UMontreal.CA imapd[26748]: imap service init from 132.204.24.100
  13. Jan 13 04:12:42 server.IRO.UMontreal.CA imapd[26748]: Logout user=??? host=server.IRO.UMontreal.CA [132.204.24.100]
  14. Jan 13 04:13:58 server.IRO.UMontreal.CA sudo: fmserver : TTY=none ; PWD=/home/fmserver/bin ; USER=root ;
  15. COMMAND=/bin/du -sk /home/ouimet
  16. Jan 13 04:15:27 alpha.IRO.UMontreal.CA sshd2[412]: connection from "132.204.24.100"
I start my script with this code :
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. print "Gime me the filename";
  3. chop ($name = <STDIN>);
  4. my @file = $name;
  5. open(LOG,"@file") or die "Unable to open logfile:$!\n";
  6. while(<LOG>){
  7.     my @lines = <LOG>;
  8. foreach $ligne (@lignes)
  9. {  }
  10. close(LOG);
Mar 22 '08 #1
4 2116
eWish
971 Recognized Expert Contributor
What kind of log file is this? Basically you will want to loop through the file and split each line into the various chunks of data. Look into the split() function. You will need a common delimiter (ie: whitespace, tab, pipe( | ), comma ( , ) and so on.). Then either use a hash to store the data or an array foreach of the various points of interest.

You could also search CPAN for modules that might handle this task already.


--Kevin
Mar 22 '08 #2
KevinADC
4,059 Recognized Expert Specialist
1- the covered period of the log (start-end) by date and hours;
2- the total number of lines (traces) foreach adress;
3-the total numbers of traces for each service;
4-the total number of connections pop, ssh and imap;
5- the list of addresses that made a ssh connection and how many for each
6- list of adresses that sent an email by sendmail and how many for each
What have you tried so far? Where are you stuck? Do you have any idea how to start writing code to do any of the things you listed?
Mar 23 '08 #3
finelady
2 New Member
Hello,
Let me explain more what am trying to do.
I have a log file who contains these lines below :
Expand|Select|Wrap|Line Numbers
  1. Jan-13 04:12:41 server.alpha.allo.com. ipop3d[26735]: pop3 service init from 132.204.24.100
  2. Jan-13 04:12:42 server.alpha.allo.com. imapd[26748]: imap service init from 132.204.24.100
  3. Jan-13 04:05:44 client.alpha.allo.com sendmail[22674]: i0D95hr8022674: to=root, ctladdr=root (0/1), delay=00:00:01,
  4. mailer=relay, pri=30271, relay=[127.0.0.1], dsn=2.0.0, stat=Sent (i0D95hEt022675 Message accepted for delivery)
  5. Jan-13 04:15:27 Andre.alpha.allo.com sshd2[412]: connection from "132.204.24.100"
And I want to creat a script who will give me the informations below :

1- Home many lines
2-the start and end time of the log with date and time
3-How nany lines (traces) of each service
4-How many connexion of POP3, SSH and IMAP do have my log
5-The list of adresses(email) who made a SSH connexion anh how many each
6-the list of adresses (email) who sent an email true sendmail.

And all theses results I wnat to put it on a txt file and sent it by email (using sendmail) to the mail adress contained in the SYSADMIN.

I know you will not do all these things but I really need help, I am not so good in perl and have to finish this work, I really need help I start with the code bellow
Any suggestion idea is welcome, so many days now am reading lot of book and searching is the only thing left to finish my thing
Thanks in advance , here is my start code :
Expand|Select|Wrap|Line Numbers
  1. #!/usr/bin/perl
  2. use strict; use warnings;
  3.  
  4. open my $inputfh, '<', $inputfilename
  5.         or die "$!\n";
  6.  
  7.     my %hostcount;
  8.  
  9.     while (my $line = <$inputfh>) {
  10.         my @data = split /\s+/, $line;
  11.         my $host = $data[2];
  12.         $hostcount{$host} += 1;
  13.     }
  14.  
  15.     print map { "$_ $hostcount{$_}\n" } sort keys %hostcount;
Mar 25 '08 #4
eWish
971 Recognized Expert Contributor
Please do not start a new thread when you already have a thread started on the same topic and issue. I have merged the threads.

Thank You,

--Kevin
Mar 26 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

9
3982
by: Johan Holst Nielsen | last post by:
Hi, Is there any Python packages to analyse or get some information out of an PDF document... Like where the text are placed - what text are placed - fonts, embedded PDFs/fonts/images etc. Please let me know :)
35
3679
by: Troll | last post by:
Hi, I need to write a script which reads some data and reports the findings. Just to give you an idea the structure is similar to the following. Data input example: HEADING 1 ********** ColumnA ColumnB ColumnC ColumnD ColumnE
2
1979
by: Patrick Fischer | last post by:
Hello Hello I looks for a possibility to analyse html while browsing. Like a DOM Inspector. While the page is loading the analyser check the page, make a DOM tree and I can get the DOM tree. Is there a Browser extending for Firefox oder Mozilla?
3
12180
by: Phil Endecott | last post by:
Dear PostgreSQL experts, This is with version 7.4.2. My database has grown a bit recently, mostly in number of tables but also their size, and I started to see ANALYSE failing with this message: WARNING: out of shared memory ERROR: out of shared memory HINT: You may need to increase max_locks_per_transaction.
8
2093
by: novice | last post by:
Hi geeks, Can any body explain me how to analyse int the pollowing code This is the question I was asked in the interview... char *s ={ "hello", "basic", "world", "program"}; char **sPtr = { s+3, s+2, s+1, s };
0
1608
by: =?ISO-8859-1?Q?Konrad_M=FChler?= | last post by:
Hallo, ich bin auf der Suche nach einem Tool, mit dem ich unter Visual Studio 7 oder 8 eine Performance Analyse auf meinem Code durchführen kann, um zu ermitteln, wo wieviel Zeit verloren geht. Ich hab bisher nur die sündhaft teuren Produkte von DevPartner gefunden. Gibt es billigere oder gar kostenlose/OpenSource Tools, mit denen ich die Aufgabe lösen könnte? Habt vielen Dank
0
1212
by: Petr Jakes | last post by:
On the local radio station here in the Czech they announced simple contest: If listeners will hear Elton John's Sacrifice followed immediately by Madonna's Frozen they have to call to the broadcasting. First caller will get some price. I am just thinking about the concept how to analyse music stream form the PC radio card to get the signal: "first tones of Frozen were played after Sacrifice, call to the studio" :-)
1
3505
by: Naha | last post by:
Hi, I am starting a new project where I have to create a office monitoring system, whereby I need to capture images from a webcam and analyse these images using Java advanced imaging in order to determine if there are people in the images. Can someone please give me some guidance on how to do this, I am completely new to Java Advanced imaging!!!! Please...
4
2337
by: ramyamuthusamy | last post by:
Hi I want to know how to analyse the network traffic using java,,
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8831
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9552
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9249
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6796
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4607
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4877
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3315
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.