Thanks for your reply. I am new to Perl language so please be patient with me. for the first problem you mentioned, I dont understand what I should do here. GotToBTru suggested to put while (<DIAG>) first and put inside this loop the rest of the statements. maybe i misunderstand what he suggested. please help me to understand. for problem 2 i put the last as you suggested. for the third issue I completely removed the LOGFILE because I dont need it. the purpose of this script is to check a diagnostic file (.dia) which is continuously updated and once it match a statement "higher than 5 seconds" to shutdown a service and start it again. and then continue to work. below is the updated code please take a look and let me know what should i do as I am desperate :( :( :(

#!C:\Perl64\bin\perl.exe use File::Tail; my $routerip; 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 "ROUTERIP") { $routerip = $val; } 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) { 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" ; system($commandStr2); my $commandStr4 = "sc \\\\$hostName2 stop AudioSrv + >$app_root_dir\\logs\\StopServiceOutput2.txt" ; system($commandStr4); sleep(5); my $commandStr3 = "sc \\\\$hostName1 start AudioSr +v >$app_root_dir\\logs\\StartServiceOutput1.txt"; system($commandStr3); my $commandStr5 = "sc \\\\$hostName2 start AudioSr +v >$app_root_dir\\logs\\StartServiceOutput2.txt"; system($commandStr5); } $clock --; } last; } } }

In reply to Re^4: trying to implement file tail with regular expression by mkhayat
in thread trying to implement file tail with regular expression by mkhayat

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.