Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: Help e-mailing last 50 lines of log file

by samgold (Scribe)
on Jul 19, 2002 at 00:22 UTC ( #183094=note: print w/replies, xml ) Need Help??


in reply to Help e-mailing last 50 lines of log file

This will read a file backwards untill yestersdays date. If your log file is large try file::Readbackwards.
my $file; my @lines; open FH, 'yourlogfile.log'; @lines = <FH>; LINE: while ($file = pop @lines) { if ( $file =~ m/^ERR*/ ) { print "$file\n"; } last LINE if ($file !~ m/^$today*/ && $file =~ m/^(\S+\s+\S+\s+\d+)\s+\d+:\d+:\d+\s+(\d+)/x ); }
Or you can try this...
Recommended by runrig
If the log file is large (which log files sometimes tend to be) then you might want to use File::ReadBackwards or risk getting an 'Out of memory' error.

I hope that helps.
Sam

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://183094]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (3)
As of 2022-08-08 01:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?