perladdict has asked for the wisdom of the Perl Monks concerning the following question:
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 Advanceuse 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;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to read the last updated lines from a log file
by frozenwithjoy (Priest) on May 30, 2013 at 04:41 UTC | |
by johngg (Canon) on May 30, 2013 at 11:46 UTC | |
|
Re: How to read the last updated lines from a log file
by poj (Abbot) on May 30, 2013 at 07:30 UTC | |
|
Re: How to read the last updated lines from a log file
by davido (Cardinal) on May 30, 2013 at 17:24 UTC | |
|
Re: How to read the last updated lines from a log file
by Anonymous Monk on May 30, 2013 at 04:39 UTC | |
|
Re: How to read the last updated lines from a log file
by t_rex_joe (Sexton) on May 30, 2013 at 17:20 UTC |