Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
tye,
Thank you very much for the insight. I have "borrowed" a great deal of your code and came up with the following:

#!/usr/bin/perl -w use strict; use Time::Local; chdir "/var/spool/wt400/gateways/$ARGV[0]" or exit; mkdir "capture", 0755 unless (-d "capture"); my $Dir = $ARGV[1]; my $ListTime = 0; my $BufferSize = 64 * 1024; my $MaxLen = 0; my %Traps; my @GrepList; my $GrepString; my $Counter = 1; my $Size; my $Prev; my $Now; my $NF; while (1) { if ($Counter > 20 || ! @GrepList) { if ( (stat("traplist.$Dir"))[9] gt $ListTime ) { $ListTime = (stat(_))[9]; open (LIST,"traplist.$Dir"); while (<LIST>) { next if ($_ =~ /^Created\t\tExpires/ || $_ =~ /^ *$/); my @Fields = split "\t" , $_; my($mon, $day, $year, $hour, $min) = split ?[-/:]? , $Fields[1]; my $Expiration = timelocal(0, $min, $hour, $day, $mon -1, $year + + 100); $Traps{"$Fields[6]"} = [ $Expiration,$Fields[2],$Fields[5],$Fields +[7] ]; } close (LIST); } } @GrepList = (); $Now = time; foreach my $trap (keys %Traps) { push @GrepList,$Traps{$trap}[3] unless (($Traps{$trap}[0] < $Now && +$Traps{$trap}[1]) || $trap eq "SIZE"); } map { $MaxLen = length($_) if length($_) > $MaxLen } @GrepList; $BufferSize = 2 * $MaxLen if ($BufferSize < 2 * $MaxLen); if (exists $Traps{"SIZE"} && $Traps{"SIZE"}[1]) { $Size = $Traps{"SIZE"}[2] unless ($Traps{"SIZE"}[0] < $Now && $Traps +{"SIZE"}[2] > 0); } exit unless (@GrepList || $Size); $GrepString = join '|', map quotemeta $_, @GrepList; $GrepString = qr/($GrepString)/i; if ($Dir eq "out") { @ARGV = <out/do*>; } elsif ($Dir eq "in") { @ARGV = <in/di*>; } else { @ARGV = <out/do* in/di*> } if (@ARGV) { $/=\$BufferSize; $Prev= ""; while (<>) { $_ =~ tr/\n//d; if(($Prev.$_) =~ /$GrepString/) { ($NF = "$ARGV-$+") =~ s/^.*\///; rename $ARGV , "capture/$NF"; close (ARGV); $Prev = ""; } if (eof) { $Prev = ""; } else { $Prev = substr($_,-$MaxLen); } } } $/ = "\n"; ++$Counter; sleep 3 }

This provides 10X more functionality the original shell script did.
I would appreciate any advice on how it could be made to go faster and still be efficient.

L~R


In reply to Re: Re: Shell Script Woes (tye's try) by Limbic~Region
in thread Shell Script Woes by Limbic~Region

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 making s'mores by the fire in the courtyard of the Monastery: (8)
As of 2024-04-19 14:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found