Hi Monks,
I have implemented a script which sends the last modified log file via mail.But as this file is long user unable to recognize the latest files processed status in the log, They needed the last update lines from the log
Below is the code i tried to send the log.
use Posix; use Utils; $now = localtime(); %months = ("jan"=>1,.... "Dec"=>12); @now = split(" ",$now); $month $months{$now[1]}; $year = $now[-1]; $date = $now[-2]; $month = sprintf("%2d",$month); $date = sprintf("%2d",$date); $logdate = "$year$month$date"; $logpat = "xxxx"; opendir(FD,"$logpath\20130507.log") or die "$!\n"; @folders = map { [stat "$logpath/$_",$_] } grep (!/^\.\.?$/,readdir(FD +); close(FD); #fetching the last modified log sub rev_by_date { $b->[9] <=> $a->[9] } @sorted_list = sort rev_by_date @folders; @newlist = @{$sorted_list[0]}; $latestlog = pop(@newlist); $log = "$logpath\$latestlog"; open(F,"$log") or die "$!\n"; @logcontent = <F>; close(F); sendmail($now,\@logcontent); sub sendmail { my($recdate,$content) = @_; my @list = @$content; my $mail_body; my $ToEmailAdd = "xxxx.com"; my $subject = "Server archival completed"; my $from = "xxxx"; my $email_body = "some String"; $email_body .= "@list" . \n";; $osmtp = Net::SMPT->new("xxxx.com",Timeout =>60); $osmpt->mail($from); $osmpt->to($ToEmailAdd); $osmpt->date(); $osmpt->datasend("From: $from"); $osmpt->datasend("To: $TOEmailAdd"); $osmpt->datasend("Subject: $subject"); $osmpt->datasend("body: $email_body"); $osmpt->quit;

But i need to send only the last updated lines as log to the user by eamil. The log is having below tags for each didderent date. <START date= "Tue May 720:10: 32 2013"><USER></USER>/br> <FNAME>filenames</FNAME><RECNAME>recordname</RECNAME><RECLOG>logpath</RELOG>
sone lines in between....
..........
<files processed="10" recorded = "0" failed = "10" rejected = "0">
<END> date = "Tue May 720:10: 32 2013"/>
</START>
The above tags are repeated for the different dates in the log, i need to send only the last occurence of the log(latest updted content)<START>....</START> content.

Dear Monks suggest me how i need to parse the log with only last occurence of of <START>..../<START> log content
Thank you Very Much in Advance

In reply to How to read the last updated lines from a log file by perladdict

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.