Log Monitoring through Perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Log Monitoring through Perl
# 1  
Old 06-25-2008
Log Monitoring through Perl

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. Smilie

Thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Monitoring script for a log file

Hi, I need to get a script working to monitor a log file and throw an alert via mailx as soon as a particular error is encountered. I do not want repeatative email notifications of same error so simply cat logfile and grepping the error would not work. Here is what i planned but it seems... (2 Replies)
Discussion started by: roshan.171188
2 Replies

2. Shell Programming and Scripting

Tomcat Monitoring log file

Hi, I ned to monitor the tomcat log file called "catalina.out" for "OutOfMemory" ,"java.sql.SQLException" and "Error" error. the script should monitor this file (catalina.out) and send us the mail as soon as it finds the string "Out of memory" or "java.sql.SQLException" or "Error" in the... (2 Replies)
Discussion started by: mnmonu
2 Replies

3. Shell Programming and Scripting

Help with FTP Monitoring Using Perl

Hi, Can anyone help me to start a monitoring script in perl of a FTP server. (2 Replies)
Discussion started by: phanik143
2 Replies

4. Shell Programming and Scripting

Monitoring a users log in time?

how do i start with this guys? Sample run: $ LOGTIME it2015678 <enter> User it2015678 is CRUZ Tommy H And has logged on to the system for: 8 hours 12 minutes from the time this script was run. (1 Reply)
Discussion started by: skypigeon
1 Replies

5. Shell Programming and Scripting

log monitoring

Hi All; I have a log file(dynamic) which i need to monitor; the format of the log file is as follows #Session ID STATUS The status can be one of the three /starting ;/loading ;/success Example #Session ID STATUS ABC /started.html XYZ /started.html ABC /loading.html ABC... (2 Replies)
Discussion started by: maverick_here
2 Replies

6. Infrastructure Monitoring

Zabbix Template and PERL Script for Monitoring Apache2

Hello, Kindly find attached a copy of the Zabbix template and PERL script we are using to monitor our Apache2 server. Here are the entries for zabbix_agentd.conf UserParameter=apache2.total_accesses,/etc/zabbix/zabbix_apache2.pl|cut -f1 -d":"... (4 Replies)
Discussion started by: Neo
4 Replies

7. Shell Programming and Scripting

Monitoring log file

Hi, I ned to monitor the tomcat log file called "catalina.out" for "Out of memory" error. the script should monitor this file and send us the mail as soon as it finds the string "Out of memory" in the file. can ypu suggest me which is the best way to do this? (4 Replies)
Discussion started by: shivanete
4 Replies

8. Windows & DOS: Issues & Discussions

Log monitoring in windows

Hi, I'd like to know if there is a way to monitor a log file conitnuously for one or more strings and if found, send an alarm. It should also take care not to inlcude the old log file entries. Thanks. (2 Replies)
Discussion started by: er_ashu
2 Replies

9. UNIX for Dummies Questions & Answers

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... (1 Reply)
Discussion started by: solitare123
1 Replies

10. UNIX for Dummies Questions & Answers

log monitoring

Hi there, I have an application runnig on HP_UX which logs critical mesages to a log file. What I would like to do is tail the log file and report on new messages. Easy....I here you say. The log file is continuing to be written to and the check scritp will be executed from cron. I was... (2 Replies)
Discussion started by: nhatch
2 Replies
Login or Register to Ask a Question