Hi
I want to script to monitor the logs.
1. Log file keep getting written ever min.
2. Whenever an exception / WARNING comes it has to send that message to chat server (
I have the script for chat )server)
3. I has to read the word like exception and warning from flat file
4. Name of the file also from flat file
How to do this?
I have some portion of script also
======================
($FILENAME)[EMAIL PROTECTED];
$regex = "Exception";
@buffer = ();
GetOptions(\%opt, qw(help files=s)) or die "Invalid options.\n";
showHelpMessage() if ($opt{'help'});
open (LOGFILE,"$FILENAME");
for (;;)
{
for ($cursorposition = tell(LOGFILE); $_ = <LOGFILE>; $cursorposition = tell(LOGFILE))
{
$line = $_;
chomp $line;
push @buffer, $line;
if (@buffer > 10)
{
shift @buffer;
}
if ($line =~/$regex/)
{
open (MAILFILE, ">mailfile");
my $oldfh1 = select MAILFILE; $| = 1; select MAILFILE;
$j = 0;
foreach $previousLine (@buffer)
{
$j++;
print MAILFILE "$previousLine \n";
}
$i = 0;
$pos = tell LOGFILE;
while(<LOGFILE>)
{
$i++;
if ($i > 10)
{
last;
}
$var = $_;
print MAILFILE "$var \n";
}
close(MAILFILE);
seek(LOGFILE, $pos, 0);
$msg=`cat mailfile`;
DoChat($msg);
sub DoChat
{
my @msg = @_;
GetIrcConnection("$chatuser","$chatirc");
SendIrc("$chatchannel","$msg");
QuitIrc;
}
}
}
sleep(1);
seek(LOGFILE, $cursorposition, 0);
}
sub showHelpMessage
{
print <<EOF;
Usage :
./monotorLogs.pl <LOGFILENAME>
The Objective of the Script is to monitor the logs and Capture the error
information.
Assumption:
1.PERL is installed and Path is set to perl
2.Chat Server Library files present in lib
3.monotorLogs.pl has execute permission
Here in the PERL Script we are calling two variable.
$FILENAME and $regex
$FILENAME --> Log file names to monitor. Add the log file names in "filelist ".
$regex --> Preset in "monotorLogs.pl". You can add the search pattern words.
EOF
exit;
}
Kindly let me know
If you have better script kindly send me
bye
sreedhar
Visit our website at http://www.ubs.com
This message contains confidential information and is intended only
for the individual named. If you are not the named addressee you
should not disseminate, distribute or copy this e-mail. Please
notify the sender immediately by e-mail if you have received this
e-mail by mistake and delete this e-mail from your system.
E-mail transmission cannot be guaranteed to be secure or error-free
as information could be intercepted, corrupted, lost, destroyed,
arrive late or incomplete, or contain viruses. The sender therefore
does not accept liability for any errors or omissions in the contents
of this message which arise as a result of e-mail transmission. If
verification is required please request a hard-copy version. This
message is provided for informational purposes and should not be
construed as a solicitation or offer to buy or sell any securities or
related financial instruments.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>