in reply to Re: trying to implement file tail with regular expression
in thread trying to implement file tail with regular expression
Thank you very much for your help. I did what you said but the issue is once I reach to while (<DIAG>) it hang for some reason. please help!!
use File::Tail; my $diagfile; my $Checkoutput; my $hostName1; my $hostName2; sub init { my ($dir) = @_; my $line; my $var; my $val; open (LREP2, "$dir/config/param.ini"); while ($line = <LREP2>) { chop $line; ($var,$val) = split(/=/, $line); if ($var eq "DIAGFILE") { $diagfile = $val; } if ($var eq "CHECKFILE") { $Checkoutput = $val; } if ($var eq "HOSTNAME1") { $hostName1 = $val; } if ($var eq "HOSTNAME2") { $hostName2 = $val; } } close LREP2; } #MAIN die "Usage: $0 <app_root_dir>" unless @ARGV == 1; my $app_root_dir = shift; &init($app_root_dir); my $line; open (DIAG, "$diagfile"); my $ref=tie *DIAG,"File::Tail",(name=> $diagfile); my $clock = 0; while (<DIAG>){ while (1) { open LOGFILE, ">>$app_root_dir/logs/detailedlog.log"; while ($line = <DIAG>) { if ($line =~ /is higher than 5 seconds/) { if ($clock == 0) { $clock = 60; my $commandStr2 = "sc \\\\$hostName1 stop AudioSrv + >$app_root_dir\\logs\\StopServiceOutput1.txt" ; print LOGFILE "about to execute=$commandStr2\n"; system($commandStr2); print LOGFILE "just executed=$commandStr2\n"; my $commandStr4 = "sc \\\\$hostName2 stop AudioSrv + >$app_root_dir\\logs\\StopServiceOutput2.txt" ; print LOGFILE "about to execute=$commandStr4\n"; system($commandStr4); print LOGFILE "just executed=$commandStr4\n"; sleep(5); my $commandStr3 = "sc \\\\$hostName1 start AudioSr +v >$app_root_dir\\logs\\StartServiceOutput1.txt"; print LOGFILE "about to execute=$commandStr3\n"; system($commandStr3); print LOGFILE "just executed=$commandStr3\n"; my $commandStr5 = "sc \\\\$hostName2 start AudioSr +v >$app_root_dir\\logs\\StartServiceOutput2.txt"; print LOGFILE "about to execute=$commandStr5\n"; system($commandStr5); print LOGFILE "just executed=$commandStr5\n"; } $clock --; sleep(1); } close LOGFILE; } sleep(65); } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: trying to implement file tail with regular expression
by Athanasius (Archbishop) on Feb 15, 2016 at 06:54 UTC | |
by mkhayat (Initiate) on Feb 16, 2016 at 08:47 UTC | |
by poj (Abbot) on Feb 16, 2016 at 12:01 UTC | |
by mkhayat (Initiate) on Feb 17, 2016 at 05:29 UTC | |
by poj (Abbot) on Feb 17, 2016 at 07:40 UTC | |
|