<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: shell script for log parsing in Operating System - Linux</title>
    <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700493#M103333</link>
    <description>Hi Shiv, &lt;BR /&gt;&lt;BR /&gt;How to verify whether perl would be available on my hpux box ? Does it come by default on all hpux servers ?&lt;BR /&gt;&lt;BR /&gt;To answer your question, perl comes default on 11.11 and 11.23. You can find the version of perl by # perl -v or # swlist |grep -i perl &lt;BR /&gt;&lt;BR /&gt;If you want to download perl, &lt;A href="http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=PERL" target="_blank"&gt;http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=PERL&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Or from Procura's site, &lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://mirrors.develooper.com/hpux/" target="_blank"&gt;http://mirrors.develooper.com/hpux/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;-Arun</description>
    <pubDate>Sun, 01 Jan 2006 22:45:57 GMT</pubDate>
    <dc:creator>Arunvijai_4</dc:creator>
    <dc:date>2006-01-01T22:45:57Z</dc:date>
    <item>
      <title>shell script for log parsing</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700485#M103325</link>
      <description>Dear Sir,&lt;BR /&gt;&lt;BR /&gt;I want to find lines containing error message "500 Server Error: 20-0002" in log file. &lt;BR /&gt;&lt;BR /&gt;A sample entry in the log containing the error message is shown below:&lt;BR /&gt;&lt;BR /&gt;[15/Dec/2005:10:17:47-28247-160-0] Process - Exiting with HTTP 500 Server Error: 20-0002&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;I want to parse this log for the error "500 Server Error: 20-0002" between time period 10:00:00 to 18:00:14&lt;BR /&gt;for 2 dates (1) between 10/Dec/2005 to 15/Dec/2005 (2) only on 15/Dec/2005&lt;BR /&gt;&lt;BR /&gt;Can someone suggest a shell script ?&lt;BR /&gt;&lt;BR /&gt;Regards,&lt;BR /&gt;Shiv&lt;BR /&gt;</description>
      <pubDate>Sun, 01 Jan 2006 00:12:10 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700485#M103325</guid>
      <dc:creator>Shivkumar</dc:creator>
      <dc:date>2006-01-01T00:12:10Z</dc:date>
    </item>
    <item>
      <title>Re: shell script for log parsing</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700486#M103326</link>
      <description>hits=$(grep "500 Server Error: 20-0002" /var/adm/syslog.log | wc -l)&lt;BR /&gt;&lt;BR /&gt;if [ $hits -ge 1 ]&lt;BR /&gt;then&lt;BR /&gt;# insert notify code here.&lt;BR /&gt;else&lt;BR /&gt;  echo all is well in systemland&lt;BR /&gt;fi&lt;BR /&gt;&lt;BR /&gt;Adjust the file being grepped to your needs.&lt;BR /&gt;&lt;BR /&gt;SEP</description>
      <pubDate>Sun, 01 Jan 2006 06:13:37 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700486#M103326</guid>
      <dc:creator>Steven E. Protter</dc:creator>
      <dc:date>2006-01-01T06:13:37Z</dc:date>
    </item>
    <item>
      <title>Re: shell script for log parsing</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700487#M103327</link>
      <description>Hi,&lt;BR /&gt;&lt;BR /&gt;one simple approach would be to use awk to search for the lines in between to strings, e.g.:&lt;BR /&gt;&lt;BR /&gt;$ awk '/\[10\/Dec\/2005:10/,/\[10\/Dec\/2005:18/' your_logfile&lt;BR /&gt;&lt;BR /&gt;the awk pattern is basically&lt;BR /&gt;/from/,/to/&lt;BR /&gt;the backslashes are for escaping the slashes in the search strings.&lt;BR /&gt;&lt;BR /&gt;&lt;BR /&gt;An awk statement can be combined with grep in a script, e.g.:&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/sh&lt;BR /&gt;awk '/\[10\/Dec\/2005:10/,/\[10\/Dec\/2005:18/' $1 | while read line&lt;BR /&gt;do&lt;BR /&gt;grep "Process - Exiting with HTTP 500 Server Error: 20-0002"&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;which you can run using your infile as $1.&lt;BR /&gt;However, both the "from" and "to" string *must* exist in your_logfile&lt;BR /&gt;&lt;BR /&gt;I suggest you do it one day at a time.&lt;BR /&gt;&lt;BR /&gt;regards,&lt;BR /&gt;John K. &lt;BR /&gt;</description>
      <pubDate>Sun, 01 Jan 2006 13:10:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700487#M103327</guid>
      <dc:creator>john korterman</dc:creator>
      <dc:date>2006-01-01T13:10:52Z</dc:date>
    </item>
    <item>
      <title>Re: shell script for log parsing</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700488#M103328</link>
      <description>Hi Shiv:&lt;BR /&gt;&lt;BR /&gt;This becomes easy in perl.  Although this script could be improved, it provides a general guideline.  It's easy to compare date/time ranges if you translate them into epoch seconds (the number of seconds since January 1, 1970).  That's what I do here.  Since you presented your dates in the Europenan format, I honored that too.&lt;BR /&gt;&lt;BR /&gt;You an change the $pattern and/or $firstdt, $firsttm, $lastdt, $lasttm values to your needs.  Since this is a quick script, I didn't choose to pass them as arguments.&lt;BR /&gt;&lt;BR /&gt;# cat logpeek&lt;BR /&gt;&lt;BR /&gt;#!/usr/bin/perl&lt;BR /&gt;use strict;&lt;BR /&gt;use warnings;&lt;BR /&gt;use Date::Calc qw( Decode_Date_EU Date_to_Time );&lt;BR /&gt;my  ($year, $month, $day, $hour, $min, $sec);&lt;BR /&gt;my  ($date, $time, $first, $last);&lt;BR /&gt;my   @time;&lt;BR /&gt;my   $pattern = "500 Server Error: 20-0002";&lt;BR /&gt;my   $firstdt = "10 Dec 2005";&lt;BR /&gt;my   $firsttm = "10:00:00";&lt;BR /&gt;my   $lastdt  = "15 Dec 2005";&lt;BR /&gt;my   $lasttm  = "18:00:14";&lt;BR /&gt;&lt;BR /&gt;die unless (($year, $month, $day) = Decode_Date_EU($firstdt));  &lt;BR /&gt;@time  = split( /:/, $firsttm);&lt;BR /&gt;$first = Date_to_Time($year, $month, $day, $time[0], $time[1], $time[2]);&lt;BR /&gt;&lt;BR /&gt;die unless (($year, $month, $day) = Decode_Date_EU($lastdt));  &lt;BR /&gt;@time  = split( /:/, $lasttm);&lt;BR /&gt;$last  = Date_to_Time($year, $month, $day, $time[0], $time[1], $time[2]);&lt;BR /&gt;&lt;BR /&gt;while (&amp;lt;&amp;gt;) {&lt;BR /&gt;    next unless m/$pattern/i;&lt;BR /&gt;    next unless m/\[(\d+.+\d{4}):(\d+:\d+:\d+)/;&lt;BR /&gt;&lt;BR /&gt;    $date = $1;&lt;BR /&gt;    @time = split( /:/, $2);&lt;BR /&gt;    ($hour, $min, $sec) = (@time) [0..2];&lt;BR /&gt;&lt;BR /&gt;    if (($year, $month, $day) = Decode_Date_EU($date)) {&lt;BR /&gt;        $time = Date_to_Time($year, $month, $day, $hour, $min, $sec);&lt;BR /&gt;        next if ($time &amp;lt; $first or $time &amp;gt; $last);&lt;BR /&gt;        print $_;&lt;BR /&gt;    }&lt;BR /&gt;}&lt;BR /&gt;1;&lt;BR /&gt;#_jrf_&lt;BR /&gt;&lt;BR /&gt;Run the script, passing it the name of your log file, as for example:&lt;BR /&gt;&lt;BR /&gt;# ./logpeek logfile&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sun, 01 Jan 2006 13:49:00 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700488#M103328</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-01-01T13:49:00Z</dc:date>
    </item>
    <item>
      <title>Re: shell script for log parsing</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700489#M103329</link>
      <description>I wish a very happy and prosperous new year to forum moderators and members of this forum. This is really a great forum and i have never come across a forum on unix like this. I wanted to learn unix from gurus and experts. I am grateful to hp and its great forum members here. &lt;BR /&gt;&lt;BR /&gt;warm regards to all,&lt;BR /&gt;Shiv</description>
      <pubDate>Sun, 01 Jan 2006 17:13:50 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700489#M103329</guid>
      <dc:creator>Shivkumar</dc:creator>
      <dc:date>2006-01-01T17:13:50Z</dc:date>
    </item>
    <item>
      <title>Re: shell script for log parsing</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700490#M103330</link>
      <description>How to verify whether perl would be available on my hpux box ? Does it come by default on all hpux servers ?</description>
      <pubDate>Sun, 01 Jan 2006 18:07:01 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700490#M103330</guid>
      <dc:creator>Shivkumar</dc:creator>
      <dc:date>2006-01-01T18:07:01Z</dc:date>
    </item>
    <item>
      <title>Re: shell script for log parsing</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700491#M103331</link>
      <description>Hi Shiv:&lt;BR /&gt;&lt;BR /&gt;It is available for installation in all recent releases.  You can verify that you (*should*) have it with:&lt;BR /&gt;&lt;BR /&gt;# swlist -l product perl&lt;BR /&gt;&lt;BR /&gt;If it's not installed you can get it here:&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=PERL" target="_blank"&gt;http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=PERL&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;...or an even more recent version, here, thanks to Merijn (Procura):&lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://mirrors.develooper.com/hpux/" target="_blank"&gt;http://mirrors.develooper.com/hpux/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sun, 01 Jan 2006 18:33:54 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700491#M103331</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-01-01T18:33:54Z</dc:date>
    </item>
    <item>
      <title>Re: shell script for log parsing</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700492#M103332</link>
      <description>Hi (again) Shiv:&lt;BR /&gt;&lt;BR /&gt;I should add this information.  If you do:&lt;BR /&gt;&lt;BR /&gt;# whereis perl&lt;BR /&gt;&lt;BR /&gt;You may get back something like:&lt;BR /&gt;&lt;BR /&gt;perl: /usr/bin/perl /usr/contrib/bin/perl /opt/perl/bin/perl /opt/perl_64/bin/pe&lt;BR /&gt;rl /opt/perl/man/man1/perl.1 /opt/perl_64/man/man1/perl.1&lt;BR /&gt;&lt;BR /&gt;You need to assess the version of perl that is thus available.  I have soft-linked '/opt/perl/bin/perl' and '/usr/bin/perl'.  For instance:&lt;BR /&gt;&lt;BR /&gt;# /opt/perl/bin/perl -v&lt;BR /&gt;&lt;BR /&gt;...returns (in part):&lt;BR /&gt;&lt;BR /&gt;"This is perl, v5.8.2 ..."&lt;BR /&gt;&lt;BR /&gt;This is a fairly current version.  My point is that if I do:&lt;BR /&gt;&lt;BR /&gt;# /usr/contrib/bin/perl -v &lt;BR /&gt;&lt;BR /&gt;...I see:&lt;BR /&gt;&lt;BR /&gt;This is perl, version 5.005_02 ..."&lt;BR /&gt;&lt;BR /&gt;This is the very *old* version that will exist on your system regardless of whether or not you installed a current version of perl.  You want to *at least* use a 5.8.x version.&lt;BR /&gt;&lt;BR /&gt;Regards!&lt;BR /&gt;&lt;BR /&gt;...JRF...</description>
      <pubDate>Sun, 01 Jan 2006 18:47:41 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700492#M103332</guid>
      <dc:creator>James R. Ferguson</dc:creator>
      <dc:date>2006-01-01T18:47:41Z</dc:date>
    </item>
    <item>
      <title>Re: shell script for log parsing</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700493#M103333</link>
      <description>Hi Shiv, &lt;BR /&gt;&lt;BR /&gt;How to verify whether perl would be available on my hpux box ? Does it come by default on all hpux servers ?&lt;BR /&gt;&lt;BR /&gt;To answer your question, perl comes default on 11.11 and 11.23. You can find the version of perl by # perl -v or # swlist |grep -i perl &lt;BR /&gt;&lt;BR /&gt;If you want to download perl, &lt;A href="http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=PERL" target="_blank"&gt;http://h20293.www2.hp.com/portal/swdepot/displayProductInfo.do?productNumber=PERL&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;Or from Procura's site, &lt;BR /&gt;&lt;BR /&gt;&lt;A href="http://mirrors.develooper.com/hpux/" target="_blank"&gt;http://mirrors.develooper.com/hpux/&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;-Arun</description>
      <pubDate>Sun, 01 Jan 2006 22:45:57 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700493#M103333</guid>
      <dc:creator>Arunvijai_4</dc:creator>
      <dc:date>2006-01-01T22:45:57Z</dc:date>
    </item>
    <item>
      <title>Re: shell script for log parsing</title>
      <link>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700494#M103334</link>
      <description>Use this:&lt;BR /&gt;&lt;BR /&gt;# cat test.sh&lt;BR /&gt;# Change to your log file location&lt;BR /&gt;LOGFILE=test.log&lt;BR /&gt;&lt;BR /&gt;awk '/500 Server Error: 20-0002/ { print $0; }' ${LOGFILE} | while read line&lt;BR /&gt;do&lt;BR /&gt;&lt;BR /&gt;  echo "On Dec 15th betweentime period 10:00:00 to 18:00:14"&lt;BR /&gt;  echo&lt;BR /&gt;&lt;BR /&gt;  date=$(echo ${line} | awk -F"/" '{ print $1; }' | tr -d '[')&lt;BR /&gt;&lt;BR /&gt;  if [[  $date -eq 15 ]]&lt;BR /&gt;  then&lt;BR /&gt;&lt;BR /&gt;    result=$(echo ${line} | awk -F: '{ if ( ($2 &amp;gt;= 10 || $2 &amp;lt;= 18) &amp;amp;&amp;amp; ($3 &amp;gt;= 0 || $3 &amp;lt;=0) &amp;amp;&amp;amp; ($4 &amp;lt;=14 || $4 &amp;gt;= 0) ) { print "&lt;BR /&gt;1"; }}');&lt;BR /&gt;&lt;BR /&gt;    if [[ $result -eq 1 ]]&lt;BR /&gt;    then&lt;BR /&gt;&lt;BR /&gt;       echo $line;&lt;BR /&gt;    fi&lt;BR /&gt;&lt;BR /&gt;  echo&lt;BR /&gt;  echo "Dec 10th to Dec 15th betweentime period 10:00:00 to 18:00:14"&lt;BR /&gt;  echo&lt;BR /&gt;&lt;BR /&gt;  date=$(echo ${line} | awk -F"/" '{ print $1; }' | tr -d '[')&lt;BR /&gt;&lt;BR /&gt;  if [[  $date -ge 10 &amp;amp;&amp;amp;   $date -le 15 ]]&lt;BR /&gt;  then&lt;BR /&gt;&lt;BR /&gt;    result=$(echo ${line} | awk -F"-" '{ print $1; }' | awk -F":" '{ if ( $2 &amp;gt;= 10 &amp;amp;&amp;amp; $2 &amp;lt;= 18 &amp;amp;&amp;amp; $3 &amp;gt;= 0 &amp;amp;&amp;amp; $3 &amp;lt;=0 &amp;amp;&amp;amp; $4 &amp;lt;=1&lt;BR /&gt;4 &amp;amp;&amp;amp; $4 &amp;gt;= 0 ) { print "1"; }}');&lt;BR /&gt;    if [[ $result -eq 1 ]]&lt;BR /&gt;    then&lt;BR /&gt;       echo $line;&lt;BR /&gt;    fi&lt;BR /&gt;  fi&lt;BR /&gt;&lt;BR /&gt;  fi&lt;BR /&gt;done&lt;BR /&gt;&lt;BR /&gt;-Muthu</description>
      <pubDate>Mon, 02 Jan 2006 01:24:20 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-linux/shell-script-for-log-parsing/m-p/3700494#M103334</guid>
      <dc:creator>Muthukumar_5</dc:creator>
      <dc:date>2006-01-02T01:24:20Z</dc:date>
    </item>
  </channel>
</rss>

