The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > UNIX for Dummies Questions & Answers
Google UNIX.COM


UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
pERL SCRIPT FOR MONITORING DATE/TIME STAMPS FOR START AND STOP OF APPLICAION IN A LOG FREDDIE091970 Shell Programming and Scripting 4 03-31-2008 06:59 PM
Perl script to rotate logs theninja Shell Programming and Scripting 18 03-21-2008 11:06 AM
Perl scripting rsendhilmani Shell Programming and Scripting 3 07-04-2007 11:51 PM
Perl log parcer. (for custom logs details inside) Optimus_P Shell Programming and Scripting 1 08-30-2002 02:13 PM
Perl scripting jikyj UNIX for Dummies Questions & Answers 4 05-20-2002 11:25 AM

Closed Thread
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 06-25-2008
Registered User
 

Join Date: Jun 2008
Posts: 5
Perl Scripting for monitoring logs

Hi,

I am new to perl. I want to write a perl script to monitor logs. Where i want to monitor exceptions logged or any kind of error strings. I have a dir(On Solaris) with multiple log file which keeps rolling to .gz file after some time in that same dir. These logs files size keeps on increasing till the time they rollup.

In test.cfg i have put all the log dir which i want to read. and i am copying the exception and error trace to separate files.

#!/usr/local/bin/perl -w

$config_file="/opt/solitare/perl_script/test.cfg";
unless(open(CONFIG,"/opt/solitare/perl_script/test.cfg"))
{
die("Could not open Config File");
}
@config = <CONFIG>;
foreach $temp1(@config)
{
chomp($temp1);
chdir($temp1);
system("rm -r /opt/solitare/error_log/ ");
mkdir("/opt/solitare/error_log/",0777);
opendir(DIR,$temp1) || die("not able to open $temp1 dir\n");
while ($filename= readdir(DIR))
{
chomp($filename);
if($filename =~ /\.log$/)
{
print("file name is = $filename \n");
$logfile="outfile";
system ("touch outfile");
unless (open(OUTFILE,">>outfile"))
{
die ("cannot open output file outfile\n");
}
unless(open(FILE,"$filename"))
{
die "Could not open $filename input log file.";
}
foreach $line (<FILE>)
{
if($line =~ /Exception/ || $line =~ /at[\t ]/ || $line =~ /Error/)
{
print OUTFILE ($line);
# print ($line);
}
}
rename ($logfile , "/opt/solitare/error_log/$filename.bk");
# print("Back Up FIle Name $filename.bk\n");
print("scanning of $filename file is completed\n");
close(OUTFILE);
}
}
close(FILE);
}
close(CONFIG);


If i use this script for log file which are not increasing in size or not active currently, It works fine.

I hope am clear with my query, as i have put query for the first time on any forum.

Thanks.
Forum Sponsor
  #2 (permalink)  
Old 06-25-2008
vgersh99's Avatar
Moderator
 

Join Date: Feb 2005
Location: Boston, MA
Posts: 2,999
Please don't double-post - read the rules.
Thread closed.
Google UNIX.COM
Closed Thread

Thread Tools
Display Modes




All times are GMT -7. The time now is 04:29 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008 The CEP Blog All Rights Reserved -Ad Management by RedTyger Visit The Global Fact Book

Content Relevant URLs by vBSEO 3.2.0