Hi
I want a script which continously searches for a work "MAX xonnections reached" in log file . As soon as it sees the message it needs to do series of steps
1) execute netstat command and redirect output to a file in /tmp
2) again continue monitoring the log file .
this job should run until we kill the process of script
plesae suggest asap.
Interview or Homework?
Could this help you ?
#!/usr/bin/perl
use strict;
my ($pos,$file_name_cur_date);
while (1){
open(FH,"<","inputfile") or die "FAIL:- $!\n";
if (defined ($pos)) { seek FH,$pos,0;}
while(<FH>){
if(/MAX connections reached/) {
$file_name_cur_date="/tmp/netstat_".`date '+%d%m%Y%H%M%S'`;
`netstat > $file_name_cur_date`;
sleep 5
}
}
$pos=tell FH;
close(FH);
}