using perl grep to read a log file - need some sort of loop

From: seane (seane_at_us.ibm.com)
Date: 07/28/04


Date: 28 Jul 2004 11:10:22 -0700

I read this log file twice a day using cron. Normally I should just
see one "connected" message when everything is working and if so exit
the script if not send an email to myself and then exit. Sometimes I
get a following disconnected message and I get sent an email if that
occurs. However sometimes I get a following connected message after
the first disconnected message then I am still ok. How can I read this
log and only get sent an email if the disconnected message is the last
string found or if no connected string was found at all?

I have a log file containing:
Fri Jul 23 13:53:54 2004: Agent is now connected.
Fri Jul 23 13:54:54 2004: Agent is now disconnected.
Fri Jul 23 13:55:54 2004: Agent is now connected.
Fri Jul 23 13:56:54 2004: Agent is now disconnected.

I have this code:
#!/usr/bin/perl -w
 $filein=("logfile");
 open (LOG, "<$filein");
 @logarray=<LOG>;
        ###########################################################################
 print"starting the log search for connected\n\n";
###########################################################################
$lookfor=("Agent is now connected");
 
        @match=grep{/$lookfor/}@logarray;
        if (@match) {
                      foreach(@match)
                           {
                         print ;
                           }
                        }
else
{
print"$lookfor was not found, an email has been sent.\n\n";
 # here is where I send myself the email- same as below.
        exit(1);
   }
print" Going to next step\n\n";
 
        ###########################################################################
print"STARTING THE SEARCH FOR DISCONNECTED MESSAGE\n\n";
###########################################################################
$lookfor=("Agent is now disconnected");
 
        @match=grep{/$lookfor/}@logarray;
        if (@match) {
                        foreach(@match) {
# system("echo $lookfor was found. |mail -s \"$0 - $sysName\"
user\@network.com");
        print"$lookfor was found, an email has been sent.\n";
        exit(1);
                                        }
                        }
 
print"EVERYTHING RAN OK\n\n";
 
exit(0);



Relevant Pages

  • Re: Distribution Agent fails with Access Violation
    ... Log file is not in the system32 we have searched the entire machine for it. ... I have checked the data and that looks fine, and the DTS should be ok too ... I have also restarted the SQL Agent ... > Looking for a SQL Server replication book? ...
    (microsoft.public.sqlserver.replication)
  • Re: Distribution Agent fails with Access Violation
    ... Hi Janet, i write from Italy, i have the same problem. ... > Log file is not in the system32 we have searched the entire machine for it. ... I have also restarted the SQL Agent ... > The other thing to note is that now whenever a distrubtion agent fails (for ...
    (microsoft.public.sqlserver.replication)
  • Auto Accept Agent - How do I know its working?
    ... I've recently installed and configured the Auto Accept agent to perform ... to use the Agent and to not use a delegated account to do the bookings. ... Log or a log file present in C:\Temp, ...
    (microsoft.public.exchange.admin)
  • Re: OMVS txt file problem
    ... exit 1;} ... # Create new log file and replace the active log file. ... # Wait long enough for transactions in progress to complete. ... Search the archives at http://bama.ua.edu/archives/ibm-main.html ...
    (bit.listserv.ibm-main)
  • Re: OMVS txt file problem
    ... exit 1;} ... # Create new log file and replace the active log file. ... # Wait long enough for transactions in progress to complete. ... {# Somehow report error to process owner, ...
    (bit.listserv.ibm-main)