Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

log search

by Lhamo_rin (Friar)
on Jun 11, 2003 at 23:30 UTC ( [id://265222]=CUFP: print w/replies, xml ) Need Help??

This snippet searches a log file for errors and warnings. It outputs those errors and warnings to an array. I grab this array from another file to post it in an applications message display on reboot after a power bump. Please let me know if there is a shorter way to do this. I'm a beginner so any comments are appreciated.
#!/opt/perl5/bin/perl5.005 -w #File Name: clean_start #Author: ### # #Description: The purpose of this file is to search the #rc.log file +for errors and warnings. #status. use diagnostics; open RC, "/etc/rc.log" or die "Can't open rc.log"; my @error = (grep /ERROR/i | /WARNING/i, <RC>); @message = join 'clean_start:', @error; print @message; close RC;

Replies are listed 'Best First'.
Re: log search
by particle (Vicar) on Jun 12, 2003 at 15:37 UTC

    this task can be accomplished with a perl one-liner:

    perl -ne"/error|warning/i && print" rc.log

    but if you'd like to make it a script, with full error checking, i might do something like:

    #!/opt/perl5/bin/perl5.005 -w use strict; use warnings; $|++; ## process each file passed on command line for my $file ( @ARGV ) { ## open the file for reading open( RC => "<", $file ) or die "Can't open $file"; ## print the program name and current file to be processed print "$0: $file\n"; ## print errors and warnings while(<RC>) { print if /error|warning/i } close RC; }

    ~Particle *accelerates*

      One liner with clarity and efficiency:
      perl -ne'print if /error/ or /warning/i' rc.log
      Golf:
      perl -pe'$_ x=/error|warning/i' rc.log

      Makeshifts last the longest.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-26 06:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found