Script to get the number of events from the logs.

2010-04-11 364 words 2 mins read

<a id="aptureLink_4P0PJ73NaG" style="margin: 0pt auto; padding: 0px 6px; text-align: center; display: block;" href=""><img style="border: 0px none;" title="Log analysis" src="" alt="" width="360px" height="320px" />

I was trying to do some <a class="zem_slink freebase/en/log_analysis" title="Log analysis" rel="wikipedia" href="">log analysis and finding the events in the logs. For this the logs had the Events logged as &#8221;|+Event name|&#8221; or with sending and receiving. So I wrote this little script to take care of my requirements.

First you would need to change the pattern in the <span style="color: #ff0000;">bold red and make sure that all <a class="zem_slink freebase/en/character_encoding" title="Character encoding" rel="wikipedia" href="">special characters like | or + need to be escaped with &#8221;&#8221;. So here&#8217;s the script:


#         FILE:

#        USAGE:  ./ log_filename

#  DESCRIPTION:  Get all the counters for the messages from the logs.

#      OPTIONS:  —
#         BUGS:  —
#        NOTES:  —
#       AUTHOR:  <a class="zem_slink" title="Amit Agarwal" rel="me" href="">Amit Agarwal (,
#      COMPANY:
#      VERSION:  1.0
#      CREATED:  01/15/2010 11:27:49 AM
#     REVISION:  —
open (FILE, “<$ARGV[0]“);

@names = `<a class="zem_slink freebase/en/grep" title="Grep" rel="wikipedia" href="">grep ‘<span style="color: #ff0000;">|+’ $ARGV[0]|sed -e ’s#.*|+##’ -e ’s#|.*##’|sort |uniq`;

%patterns=(’Received :’ => 0, ‘Sending :’ => 0);
for $j (@names) {

$temp = “\+$j\|”;

$patterns{$temp} = 0;
@keys = keys %patterns;

while ($line = ) {
for $i  (keys %patterns)

if ($line =~ m/$i/){

$patterns{$i} += 1;


for $j (sort keys %patterns){
printf “%40s ttt==> $patterns{$j}n”, $j;

Sample output:

Received :             ==> 41
Sending :             ==> 39

PS: If you need explanation for any of the above, dont hesitate to contact me via comments or email.<h6 class="zemanta-related-title">Related articles by Zemanta <ul class="zemanta-article-ul"> <li class="zemanta-article-ul-li"><a href="">bash one liner to change/remove test pattern from config file or text file. ( <li class="zemanta-article-ul-li"><a href="">gnome-disk-manager – the easier way to manage disks in Gnome with Palimpsest ( <li class="zemanta-article-ul-li"><a href="">Catching erroneous queries, without MySQL proxy ( <li class="zemanta-article-ul-li"><a href="">Twitter continues quest for global domination, adds media sharing to ( <li class="zemanta-article-ul-li"><a href="">Diff and Spaces ( <div class="zemanta-pixie"><a class="zemanta-pixie-a" title="Reblog this post [with Zemanta]" href=""><img class="zemanta-pixie-img" src="" alt="Reblog this post [with Zemanta]" /><span class="zem-script more-related more-info pretty-attribution paragraph-reblog">


Authored By Amit Agarwal

Amit Agarwal, Linux and Photography are my hobbies.Creative Commons Attribution 4.0 International License.

We notice you're using an adblocker. If you like our webite please keep us running by whitelisting this site in your ad blocker. We’re serving quality, related ads only. Thank you!

I've whitelisted your website.

Not now
This website uses cookies to ensure you get the best experience on our website. Learn more Got it