Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
teabag,
I know people have their own preference on coding style, but I find the following much more readable:
#!/usr/bin/perl use strict; use warnings; my $logfile = $ARGV[0] || "/var/amavis/amavis.log"; my $fprotdir = $ARGV[1] || "/var/virusmails"; my $virprog = $ARGV[2] || "f-prot"; my ($loc, $vir); open(LOGFILE, '<', $logfile) or die "Unable to open $logfile for readi +ng: $!"; while ( my $line = <LOGFILE> ) { chomp $line; if ( $line =~ /Infection:/ ) { ($loc, $vir) = ( split( / /, $line ) )[0, 3]; } elsif ( $line =~ /quarantined/ ) { my ($file, $time, $month, $day) = ( split( / /, $line ) )[12, +3, 0, 2]; my $date = "$day $month $time"; print "At $date $virprog detected a virus\nfound in $loc\n"; print "Name virus: $vir\nMessage saved as: $fprotdir/$file\n"; Checkwhosi( $file ); } } close LOGFILE or die "Unable to close $logfile : $!"; print "no viri received\n" if ! $vir; sub Checkwhosi { my $file_name = shift; my $file_fqn = "$fprotdir/$file_name"; open(VIRFILE, '<', $file_fqn) or die "Unable to open $file_fqn for + reading : $!"; my ($senderserv, $sserv2, %header); while ( my $line = <VIRFILE> ) { chomp $line; if ( $line =~ /Received:/ ) { ($senderserv, $sserv2) = ( split( / /, $line ) )[2,3]; $sserv2 =~ s/[(\[\]]//g; } elsif ( $line =~ /(From|To|Subject):/ ) { $header{ $1 } = ( split( / /, $line ) )[1]; } } print map{defined $header{$_} ? "$_: $header{$_}\n" : () } qw(To F +rom Subject); print "Virus Mailserver: $senderserv\nipadres server: $sserv2\n"; print "-" x 23, "\n"; close(VIRFILE) || die "Error closing viral log file: $!"; }
Cheers - L~R

In reply to Re: amavis logfile/viruspart parser by Limbic~Region
in thread amavis logfile/viruspart parser by teabag

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-03-28 08:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found