Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Perl Scripting for monitoring logs Post 302208858 by solitare123 on Wednesday 25th of June 2008 06:39:43 AM
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.
 

9 More Discussions You Might Find Interesting

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

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

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

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

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

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

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

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

9. 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
ExtUtils::Packlist(3pm) 				 Perl Programmers Reference Guide				   ExtUtils::Packlist(3pm)

NAME
ExtUtils::Packlist - manage .packlist files SYNOPSIS
use ExtUtils::Packlist; my ($pl) = ExtUtils::Packlist->new('.packlist'); $pl->read('/an/old/.packlist'); my @missing_files = $pl->validate(); $pl->write('/a/new/.packlist'); $pl->{'/some/file/name'}++; or $pl->{'/some/other/file/name'} = { type => 'file', from => '/some/file' }; DESCRIPTION
ExtUtils::Packlist provides a standard way to manage .packlist files. Functions are provided to read and write .packlist files. The original .packlist format is a simple list of absolute pathnames, one per line. In addition, this package supports an extended format, where as well as a filename each line may contain a list of attributes in the form of a space separated list of key=value pairs. This is used by the installperl script to differentiate between files and links, for example. USAGE
The hash reference returned by the new() function can be used to examine and modify the contents of the .packlist. Items may be added/deleted from the .packlist by modifying the hash. If the value associated with a hash key is a scalar, the entry written to the .packlist by any subsequent write() will be a simple filename. If the value is a hash, the entry written will be the filename followed by the key=value pairs from the hash. Reading back the .packlist will recreate the original entries. FUNCTIONS
new() This takes an optional parameter, the name of a .packlist. If the file exists, it will be opened and the contents of the file will be read. The new() method returns a reference to a hash. This hash holds an entry for each line in the .packlist. In the case of old- style .packlists, the value associated with each key is undef. In the case of new-style .packlists, the value associated with each key is a hash containing the key=value pairs following the filename in the .packlist. read() This takes an optional parameter, the name of the .packlist to be read. If no file is specified, the .packlist specified to new() will be read. If the .packlist does not exist, Carp::croak will be called. write() This takes an optional parameter, the name of the .packlist to be written. If no file is specified, the .packlist specified to new() will be overwritten. validate() This checks that every file listed in the .packlist actually exists. If an argument which evaluates to true is given, any missing files will be removed from the internal hash. The return value is a list of the missing files, which will be empty if they all exist. packlist_file() This returns the name of the associated .packlist file EXAMPLE
Here's "modrm", a little utility to cleanly remove an installed module. #!/usr/local/bin/perl -w use strict; use IO::Dir; use ExtUtils::Packlist; use ExtUtils::Installed; sub emptydir($) { my ($dir) = @_; my $dh = IO::Dir->new($dir) || return(0); my @count = $dh->read(); $dh->close(); return(@count == 2 ? 1 : 0); } # Find all the installed packages print("Finding all installed modules... "); my $installed = ExtUtils::Installed->new(); foreach my $module (grep(!/^Perl$/, $installed->modules())) { my $version = $installed->version($module) || "???"; print("Found module $module Version $version "); print("Do you want to delete $module? [n] "); my $r = <STDIN>; chomp($r); if ($r && $r =~ /^y/i) { # Remove all the files foreach my $file (sort($installed->files($module))) { print("rm $file "); unlink($file); } my $pf = $installed->packlist($module)->packlist_file(); print("rm $pf "); unlink($pf); foreach my $dir (sort($installed->directory_tree($module))) { if (emptydir($dir)) { print("rmdir $dir "); rmdir($dir); } } } } AUTHOR
Alan Burlison <Alan.Burlison@uk.sun.com> perl v5.16.3 2013-03-04 ExtUtils::Packlist(3pm)
All times are GMT -4. The time now is 06:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy