2 added 1830 characters in body
source | link

The following script it's about monitoring some logs, the $timestamp is at log at every line that something happens.

Example:
03:19:13.4 Begin summary update for ads.doc.inventory.InventoryItemSummary
03:19:33.9 CronServer:: DailyJob ads.tools.UpdateSummaries@17c5d6cf failed with exception ads.util.AppError: Cannot create UnitName from keys: Each
ads.util.AppError: Cannot create UnitName from keys: Each
at ads.db.DBObjectDefault.createFromKeys(DBObjectDefault.java:42)
at ads.db.DBTable.createFromKeys(DBTable.java:227)
at ads.db.DBValue.getValue(DBValue.java:621)
at ads.dbmanager.DBObjectsManager.initObjects(DBObjectsManager.java:400)
at ads.dbmanager.DBObjectsManager.reload(DBObjectsManager.java:447)
at ads.dbmanager.DBObjectsManager.loadFromStore(DBObjectsManager.java:497)
at ads.doc.inventory.InventoryItemSummary.refreshSince(InventoryItemSummary.java:173)
at ads.db.DBSummaryTable.refreshAll(DBSummaryTable.java:67)
at ads.tools.CronServer$DailyThread.run(CronServer.java:271)
[SOAPException: faultCode=SOAP-ENV:Client; msg=Error opening socket: java.net.ConnectException: Connection refused; targetException=java.lang.IllegalArgumentException: Error opening socket: java.net.ConnectException: Connection refused]
at org.apache.soap.transport.http.SOAPHTTPConnection.send(SOAPHTTPConnection.java:354)
at org.apache.soap.rpc.Call.invoke(Call.java:248)
at ads.support.SupportCall.call(SupportCall.java:56)
at ads.tools.SupportThread.run(SupportThread.java:101)
03:46:42.5 Periodic support request failed: ads.support.SupportException: Error opening socket: java.net.ConnectException: Connection refused
06:31:36.1 Upload failed: java.io.FileNotFoundException: c:/tmp/cygwin1.dll (No such file or directory)
08:01:08.0 connect from /172.22.3.28

I have this perl script

I have this perl script

The following script it's about monitoring some logs, the $timestamp is at log at every line that something happens.

Example:
03:19:13.4 Begin summary update for ads.doc.inventory.InventoryItemSummary
03:19:33.9 CronServer:: DailyJob ads.tools.UpdateSummaries@17c5d6cf failed with exception ads.util.AppError: Cannot create UnitName from keys: Each
ads.util.AppError: Cannot create UnitName from keys: Each
at ads.db.DBObjectDefault.createFromKeys(DBObjectDefault.java:42)
at ads.db.DBTable.createFromKeys(DBTable.java:227)
at ads.db.DBValue.getValue(DBValue.java:621)
at ads.dbmanager.DBObjectsManager.initObjects(DBObjectsManager.java:400)
at ads.dbmanager.DBObjectsManager.reload(DBObjectsManager.java:447)
at ads.dbmanager.DBObjectsManager.loadFromStore(DBObjectsManager.java:497)
at ads.doc.inventory.InventoryItemSummary.refreshSince(InventoryItemSummary.java:173)
at ads.db.DBSummaryTable.refreshAll(DBSummaryTable.java:67)
at ads.tools.CronServer$DailyThread.run(CronServer.java:271)
[SOAPException: faultCode=SOAP-ENV:Client; msg=Error opening socket: java.net.ConnectException: Connection refused; targetException=java.lang.IllegalArgumentException: Error opening socket: java.net.ConnectException: Connection refused]
at org.apache.soap.transport.http.SOAPHTTPConnection.send(SOAPHTTPConnection.java:354)
at org.apache.soap.rpc.Call.invoke(Call.java:248)
at ads.support.SupportCall.call(SupportCall.java:56)
at ads.tools.SupportThread.run(SupportThread.java:101)
03:46:42.5 Periodic support request failed: ads.support.SupportException: Error opening socket: java.net.ConnectException: Connection refused
06:31:36.1 Upload failed: java.io.FileNotFoundException: c:/tmp/cygwin1.dll (No such file or directory)
08:01:08.0 connect from /172.22.3.28

I have this perl script

1
source | link

Convert perl script to bash

I have this perl script

#!/usr/bin/perl

use strict;
use warnings FATAL => qw(all);

my $timestamp = qr/^\d+:\d+:\d+/;

my $block = "";
my $exception = 0;
while (<STDIN>) {

if ($block) {
# $_ is the current input line in perl.
    if ($_ =~ $timestamp) {
        print "\n\n***EXCEPTION***\n$block" if $exception;
        $block = "";
        $exception = 0;
    }
# This isn't actually a second regexp, it's a substring search.
# But you could use a regexp.
    $exception = 1 if (index($_,"Exception") >= 0);
    $block .= $_;
    next;
}
$block = $_ if ($_ =~ $timestamp);
}

and I want to convert it to bash script.

Here's what I've done so far but didn't work, #!/bin/bash

timestamp=^[0-9][0-9]\:[0-9][0-9]\:[0-9][0-9]\.[0-9]

block=""

exception=false

except=.*Exception.*

while read line
do

if [[ -z $block ]] ;
   then

    if [[ $line =~ $timestamp ]]
       then

            if [[ $exception=false ]]
               then
                     echo "\n\n***EXCEPTION***\n$block"
            fi
block=""
exception=false
    fi

    if [[ $line =~ $except ]]
       then
            exception=true
    fi

block=$block$line

fi

if [[ $line =~ $timestamp ]]
   then
    block=$line
fi

done

Any help with that?