parent
aa55caba36
commit
500d522e2d
@ -1,35 +1,39 @@ |
||||
#!/usr/bin/env perl |
||||
|
||||
use strict; |
||||
#use warnings; # Old perl |
||||
use POSIX qw(strftime); |
||||
$|++; |
||||
|
||||
sub ts { |
||||
strftime '%Y-%m-%d %H:%M:%S', localtime; |
||||
sub mj { |
||||
%_ = @_; |
||||
'{ts:"'.strftime( '%Y-%m-%d %H:%M:%S', localtime).'", proc:"s", '.join( ', ', map "$_:\"$_{$_}\"", keys%_)."}\n"; |
||||
} |
||||
|
||||
sub readg { |
||||
my $data = ''; |
||||
while( length( $data) < $_[0]) { |
||||
read( STDIN, $data, $_[0]-length($data), length($data)) or return(0); |
||||
} |
||||
$data; |
||||
} |
||||
|
||||
my$dir = shift @ARGV; |
||||
$dir =~ /^(\/.*)\/([^\/]+)$/ or die( "{ts: \"".ts."\", proc: \"s\", error: \"invalid_path_expression\", message: \"Path-Expression is invalid.\"}\n"); |
||||
$dir =~ /^(\/.*)\/([^\/]+)$/ or die( mj( error=>'invalid_path_expression', message=>'Path-Expression is invalid.')); |
||||
($dir, my$fexpr) = ($1, $2); |
||||
|
||||
chdir( $dir) or die( "{ts: \"".ts."\", proc: \"s\", error: \"change_directory\", value: \"$dir\", message: \"$!\"}\n"); |
||||
opendir( DH, '.') || die "{ts: \"".ts."\", proc: \"s\", error: \"dir_not_found\", message: \"Directory not found.\"}\n"; |
||||
chdir( $dir) or die( mj( error=>'change_directory', value=>$dir, message=>$!)); |
||||
opendir( DH, '.') or die( mj( error=>'dir_not_found', message=>'Directory not found.')); |
||||
while( my$filename = readdir( DH)) { |
||||
$filename =~ /$fexpr/ or next; |
||||
-f $filename or next; |
||||
next unless $filename =~ /$fexpr/ and -f $filename; |
||||
print pack( 'nNA*', 1, length($filename), $filename); |
||||
print STDERR "{ts: \"".ts."\", proc: \"s\", action: \"open\", file: \"$filename\"}\n"; |
||||
open F, $filename; |
||||
read STDIN, my$length, 4; # Was wenn < 4 ? |
||||
my$length = readg 4; |
||||
$length = unpack 'N', $length; |
||||
seek F, $length, 0; |
||||
while( read( F, my$r, 1400)) { |
||||
print pack( 'nNA*', 2, length($r), $r); |
||||
} |
||||
print STDERR "{ts: \"".ts."\", proc: \"s\", action: \"close\", file: \"$filename\"}\n"; |
||||
close F; |
||||
} |
||||
closedir DH; |
||||
#print STDERR "{ts: \"".ts."\", proc: \"s\", exit: 0}\n"; |
||||
exit( 0); |
||||
|
Loading…
Reference in new issue