Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: using perl grep to read a log file -
OK you ever spell check a document and you are so far off that spell
check has no idea what you are trying to spell????

That's what I feel like here.. Am I that far off base?
What I have here works it's just not exactly what I want...

At the end of the script running; I basically want to know if the
agent is still connected or has it disconnected, sometimes it will
drop connection but then reconnect on it's own and each event will
write to the log.

Any pointers/suggestions would be appreciated.




seane@us.ibm.com (seane) wrote in message news:<6634fdf1.0407281010.2f825f8b@posting.google
.com>...
> I read this log file twice a day using cron. Normally I should
> 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);

Report this thread to moderator Post Follow-up to this message
Old Post
seane
08-03-04 02:02 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:38 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.