Perl Scripting for monitoring logs


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Perl Scripting for monitoring logs
# 1  
Old 06-25-2008
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. Smilie

Thanks.
# 2  
Old 06-25-2008
Please don't double-post - read the rules.
Thread closed.
 
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If I ran perl script again,old logs should move with today date and new logs should generate.

Appreciate help for the below issue. Im using below code.....I dont want to attach the logs when I ran the perl twice...I just want to take backup with today date and generate new logs...What I need to do for the below scirpt.............. 1)if logs exist it should move the logs with extention... (1 Reply)
Discussion started by: Sanjeev G
1 Replies

2. UNIX for Dummies Questions & Answers

Scripting for deleting logs

Hi, i wants to create the script for my linux server. my system log files are getting huge frequently /root file system getting filled frequently.so wants to delete the logs when it crossed 1GB data on it. Please help me how do i create the bash script.. i use solaris 10 OS... (3 Replies)
Discussion started by: Rahulne25
3 Replies

3. UNIX for Dummies Questions & Answers

Monitoring windows logs

is it possible to monitor log files that are on a windows server, from a linux/unix host? i'm thinking that the directory that the files are located in on windows can be be mounted on the linux host, and then a script or tool can just monitor the log as though it were local? any thing wrong... (3 Replies)
Discussion started by: SkySmart
3 Replies

4. Shell Programming and Scripting

Script for monitoring logs

hi, i'm using unix solaris 5.8. I have to write a shell script for monitoring logs. whenever the logs are not updated more than one hour an alert will be send to my mail. I'm new to Unix, so could anyone help me to find this. (3 Replies)
Discussion started by: Arasu
3 Replies

5. Shell Programming and Scripting

How to stop monitoring of servers at the time of reboot through shell scripting?

We have number of servers which belongs to platforms Solaris, AIX,HP-UX and LINUX. Monitoring tool 'Patrol Agent' process run on the servers to check for the server health and communicate with the Patrol server through the port 5181. During scheduled reboot and maintenance of servers we do receive... (1 Reply)
Discussion started by: subharai
1 Replies

6. Shell Programming and Scripting

Call Shell scripting from Perl Scripting.

Hi How to call a shell scripting through a Perl scripting? Actually I need some value from Shell scripting and passes in the Perl scripting. So how can i do this? (2 Replies)
Discussion started by: anupdas
2 Replies

7. Shell Programming and Scripting

file monitoring using unix scripting on shared drive

Hi all, I have a query and need advise. is it possible to have a script which will monitor file/s on network shared drive (windows machine)? Is there a way i can monitor a file is available on shared drive and move it over to unix machine for further processing? Any guidance or advice much... (3 Replies)
Discussion started by: zulfikarmd
3 Replies

8. Shell Programming and Scripting

Concatenate Logs - Perl Question

Hi All, I am fresh to perl and had been using shell scripting in my past experiences. In my part of perl program, i am trying to run a application command ccm stop, which should give some string output as the result. The output (error or sucess) has to be returned to an exisiting log file.... (4 Replies)
Discussion started by: ganga.dharan
4 Replies

9. Shell Programming and Scripting

Perl script to rotate logs

I have a shell script that will gzip/tar/archive application logs that are over 20 days old which works just fine, but I would like to convert to a Perl script. Problem is, I'm a beginner with Perl and all attempts so far have failed. Basicaly I have a log dir /app/logs that contains several... (18 Replies)
Discussion started by: theninja
18 Replies
Login or Register to Ask a Question