allineato all'ultima versio di aseDB
This commit is contained in:
@@ -31,15 +31,23 @@ sub getUnitName { # parm => file received ($trfile)
|
|||||||
my ( $fileDate, $fileTime );
|
my ( $fileDate, $fileTime );
|
||||||
my ( $unittype, $unit );
|
my ( $unittype, $unit );
|
||||||
my ( $filenamecsv, $path, $suffix ) = fileparse( $filename, qr/\.[^.]*/ );
|
my ( $filenamecsv, $path, $suffix ) = fileparse( $filename, qr/\.[^.]*/ );
|
||||||
if ( $filenamecsv =~ m/^(\d\d_\d\d\d\d_|)(\d\d\d\d\d\d\d\d\d\d\d\d\d\d_)(G201_ID\d\d\d\d_DT\d\d\d\d)$/i ) { # GD201
|
if ( $filenamecsv =~ m/^G201_ID\d\d\d\d_DT\d\d\d\d_\d*$/i ) { # G201
|
||||||
my @strings = $filenamecsv =~ /(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2})_(.{1,4})_(.{1,6})_(.{1,6}).*/;
|
my @strings = $filenamecsv =~
|
||||||
$fileDate = $strings[0] . "/" . $strings[1] . "/" . $strings[2];;
|
/(.{1,4})_(.{1,6})_(.{1,6})_(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2}).*/;
|
||||||
$fileTime = $strings[3] . ":" . $strings[4] . ":" . $strings[5];
|
$unittype = $strings[0];
|
||||||
$unittype = $strings[6];
|
$unit = $strings[1];
|
||||||
$unit = $strings[7];
|
$fileDate = $strings[3] . "/" . $strings[4] . "/" . $strings[5];
|
||||||
} else {
|
$fileTime = $strings[6] . ":" . $strings[7] . ":" . $strings[8];
|
||||||
|
}
|
||||||
|
elsif ( $filenamecsv =~ m/^D2W_ID\d\d\d\d_DT\d\d\d\d$/i ) {
|
||||||
|
my @strings = $filenamecsv =~ /(.{1,3})_(.{1,6})_(.{1,6}).*/;
|
||||||
|
$unittype = $strings[0];
|
||||||
|
$unit = $strings[1];
|
||||||
|
}
|
||||||
|
else {
|
||||||
open FILE, $filename
|
open FILE, $filename
|
||||||
or warn getTimeStamp("log") . " >> Error: opening input file $filename\n";
|
or warn getTimeStamp("log")
|
||||||
|
. " >> Error: opening input file $filename\n";
|
||||||
( $fileDate, $fileTime ) = split( /\s/, <FILE> );
|
( $fileDate, $fileTime ) = split( /\s/, <FILE> );
|
||||||
( $unittype, $unit ) = split( /\s/, uc <FILE> );
|
( $unittype, $unit ) = split( /\s/, uc <FILE> );
|
||||||
$unit =~ s/;+$//;
|
$unit =~ s/;+$//;
|
||||||
@@ -66,51 +74,84 @@ my $tail = new File::SmartTail;
|
|||||||
$tail->WatchFile( -file => $readingFile, -type => "UNIX", -timeout => '10' );
|
$tail->WatchFile( -file => $readingFile, -type => "UNIX", -timeout => '10' );
|
||||||
|
|
||||||
while ( my $line = $tail->GetLine() ) {
|
while ( my $line = $tail->GetLine() ) {
|
||||||
if (((index($line, $ftpuser) != -1) or (index($line, $ftpuser1) != -1)) and (index($line, $recvOKstr) != -1)) {
|
if (
|
||||||
my (undef, undef, undef, $truser, undef, $trip, undef, $trfile, $trstat) = split(/[\"\[\]]/, $line);
|
(
|
||||||
my ($login,$pass,$uid,$gid) = getpwnam($truser) or warn getTimeStamp("log") . " >> $truser not in passwd file.\n";
|
( index( $line, $ftpuser ) != -1 )
|
||||||
|
or ( index( $line, $ftpuser1 ) != -1 )
|
||||||
|
)
|
||||||
|
and ( index( $line, $recvOKstr ) != -1 )
|
||||||
|
)
|
||||||
|
{
|
||||||
|
my (
|
||||||
|
undef, undef, undef, $truser, undef,
|
||||||
|
$trip, undef, $trfile, $trstat
|
||||||
|
) = split( /[\"\[\]]/, $line );
|
||||||
|
my ( $login, $pass, $uid, $gid ) = getpwnam($truser)
|
||||||
|
or warn getTimeStamp("log") . " >> $truser not in passwd file.\n";
|
||||||
|
|
||||||
my ( $filename, $path, $suffix ) = fileparse( $trfile, qr/\.[^.]*/ );
|
my ( $filename, $path, $suffix ) = fileparse( $trfile, qr/\.[^.]*/ );
|
||||||
|
|
||||||
if ( ((uc $suffix) eq (uc $ext))
|
if (
|
||||||
and
|
( ( uc $suffix ) eq ( uc $ext ) )
|
||||||
( $filename =~ m/^(\d\d_\d\d\d\d_|)(DT\d\d\d\d|LOC\d*|GD\d*)$/i
|
and ( $filename =~ m/^(\d\d_\d\d\d\d_|)(DT\d\d\d\d|LOC\d*|GD\d*)$/i
|
||||||
or $filename =~ m/^(\d\d_\d\d\d\d_|)(\d\d\d\d\d\d\d\d\d\d\d\d\d\d_)(G201_ID\d\d\d\d_DT\d\d\d\d)$/i) )
|
or $filename =~ m/^G201_ID\d\d\d\d_DT\d\d\d\d_\d*$/i
|
||||||
|
or $filename =~ m/^D2W_ID\d\d\d\d_DT\d\d\d\d$/i )
|
||||||
|
)
|
||||||
{
|
{
|
||||||
my $unit = getUnitName($trfile);
|
my $unit = getUnitName($trfile);
|
||||||
print getTimeStamp("log") . " >> Unit $unit - Filename $trfile\n";
|
print getTimeStamp("log") . " >> Unit $unit - Filename $trfile\n";
|
||||||
my $outpath = $path . $unit . "/received";
|
my $outpath = $path . $unit . "/received";
|
||||||
my $trnpath = $path . $unit . "/transmitted";
|
my $trnpath = $path . $unit . "/transmitted";
|
||||||
if ( !-d "$outpath" ) {
|
if ( !-d "$outpath" ) {
|
||||||
make_path "$outpath" , {mode => 0755, owner=>$truser, group=>$truser} or warn getTimeStamp("log") . " >> Failed to create path: $outpath";
|
make_path "$outpath",
|
||||||
|
{ mode => 0755, owner => $truser, group => $truser }
|
||||||
|
or warn getTimeStamp("log")
|
||||||
|
. " >> Failed to create path: $outpath";
|
||||||
}
|
}
|
||||||
if ( !-d "$trnpath" ) {
|
if ( !-d "$trnpath" ) {
|
||||||
make_path "$trnpath" , {mode => 0755, owner=>$truser, group=>$truser} or warn getTimeStamp("log") . " >> Failed to create path: $trnpath";
|
make_path "$trnpath",
|
||||||
|
{ mode => 0755, owner => $truser, group => $truser }
|
||||||
|
or warn getTimeStamp("log")
|
||||||
|
. " >> Failed to create path: $trnpath";
|
||||||
}
|
}
|
||||||
my $timestamp = getTimeStamp();
|
my $timestamp = getTimeStamp();
|
||||||
my $dest = $outpath . "/" . $filename . "_" . $timestamp . $suffix;
|
my $dest = $outpath . "/" . $filename . "_" . $timestamp . $suffix;
|
||||||
my $send = $trnpath . "/" . $filename . "_" . $timestamp . $suffix;
|
my $send = $trnpath . "/" . $filename . "_" . $timestamp . $suffix;
|
||||||
if ( !move $trfile, $dest ) {
|
if ( !move $trfile, $dest ) {
|
||||||
warn getTimeStamp("log") . " >> Move $trfile -> $dest failed: $!";
|
warn getTimeStamp("log")
|
||||||
} else {
|
. " >> Move $trfile -> $dest failed: $!";
|
||||||
|
}
|
||||||
|
else {
|
||||||
print getTimeStamp("log") . " >> Moved $trfile -> $dest.\n";
|
print getTimeStamp("log") . " >> Moved $trfile -> $dest.\n";
|
||||||
chmod 0664, $dest;
|
chmod 0664, $dest;
|
||||||
my @fname = ($dest);
|
my @fname = ($dest);
|
||||||
chown $uid, $gid, @fname;
|
chown $uid, $gid, @fname;
|
||||||
}
|
}
|
||||||
my $ftp = Net::FTP->new($hostname, Timeout => 20, Debug => 0, Passive => 0)
|
my $ftp = Net::FTP->new(
|
||||||
or warn getTimeStamp("log") . " >> Cannot connect to $hostname: $@";
|
$hostname,
|
||||||
|
Timeout => 20,
|
||||||
|
Debug => 0,
|
||||||
|
Passive => 0
|
||||||
|
)
|
||||||
|
or warn getTimeStamp("log")
|
||||||
|
. " >> Cannot connect to $hostname: $@";
|
||||||
if ( $ftp->login( $username, $password ) ) {
|
if ( $ftp->login( $username, $password ) ) {
|
||||||
if ( $ftp->put( $dest, $filename . $suffix ) ) {
|
if ( $ftp->put( $dest, $filename . $suffix ) ) {
|
||||||
if ( !move $dest, $send ) {
|
if ( !move $dest, $send ) {
|
||||||
warn getTimeStamp("log") . " >> Move $dest -> $send failed: $!";
|
warn getTimeStamp("log")
|
||||||
} else {
|
. " >> Move $dest -> $send failed: $!";
|
||||||
print getTimeStamp("log") . " >> Moved $dest -> $send.\n";
|
|
||||||
}
|
}
|
||||||
} else {
|
else {
|
||||||
warn getTimeStamp("log") . " >> Put $dest failed ", $ftp->message;
|
print getTimeStamp("log")
|
||||||
|
. " >> Moved $dest -> $send.\n";
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
|
else {
|
||||||
|
warn getTimeStamp("log") . " >> Put $dest failed ",
|
||||||
|
$ftp->message;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
warn getTimeStamp("log") . " >> Cannot login ", $ftp->message;
|
warn getTimeStamp("log") . " >> Cannot login ", $ftp->message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user