allineato all'ultima versio di aseDB

This commit is contained in:
2020-11-12 21:52:45 +01:00
parent 2088a289fa
commit 20fd892060

View File

@@ -31,15 +31,23 @@ sub getUnitName { # parm => file received ($trfile)
my ( $fileDate, $fileTime );
my ( $unittype, $unit );
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
my @strings = $filenamecsv =~ /(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2})_(.{1,4})_(.{1,6})_(.{1,6}).*/;
$fileDate = $strings[0] . "/" . $strings[1] . "/" . $strings[2];;
$fileTime = $strings[3] . ":" . $strings[4] . ":" . $strings[5];
$unittype = $strings[6];
$unit = $strings[7];
} else {
if ( $filenamecsv =~ m/^G201_ID\d\d\d\d_DT\d\d\d\d_\d*$/i ) { # G201
my @strings = $filenamecsv =~
/(.{1,4})_(.{1,6})_(.{1,6})_(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2}).*/;
$unittype = $strings[0];
$unit = $strings[1];
$fileDate = $strings[3] . "/" . $strings[4] . "/" . $strings[5];
$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
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> );
( $unittype, $unit ) = split( /\s/, uc <FILE> );
$unit =~ s/;+$//;
@@ -66,51 +74,84 @@ my $tail = new File::SmartTail;
$tail->WatchFile( -file => $readingFile, -type => "UNIX", -timeout => '10' );
while ( my $line = $tail->GetLine() ) {
if (((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";
if (
(
( 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/\.[^.]*/ );
if ( ((uc $suffix) eq (uc $ext))
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) )
if (
( ( uc $suffix ) eq ( uc $ext ) )
and ( $filename =~ m/^(\d\d_\d\d\d\d_|)(DT\d\d\d\d|LOC\d*|GD\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);
print getTimeStamp("log") . " >> Unit $unit - Filename $trfile\n";
my $outpath = $path . $unit . "/received";
my $trnpath = $path . $unit . "/transmitted";
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" ) {
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 $dest = $outpath . "/" . $filename . "_" . $timestamp . $suffix;
my $send = $trnpath . "/" . $filename . "_" . $timestamp . $suffix;
if ( !move $trfile, $dest ) {
warn getTimeStamp("log") . " >> Move $trfile -> $dest failed: $!";
} else {
warn getTimeStamp("log")
. " >> Move $trfile -> $dest failed: $!";
}
else {
print getTimeStamp("log") . " >> Moved $trfile -> $dest.\n";
chmod 0664, $dest;
my @fname = ($dest);
chown $uid, $gid, @fname;
}
my $ftp = Net::FTP->new($hostname, Timeout => 20, Debug => 0, Passive => 0)
or warn getTimeStamp("log") . " >> Cannot connect to $hostname: $@";
my $ftp = Net::FTP->new(
$hostname,
Timeout => 20,
Debug => 0,
Passive => 0
)
or warn getTimeStamp("log")
. " >> Cannot connect to $hostname: $@";
if ( $ftp->login( $username, $password ) ) {
if ( $ftp->put( $dest, $filename . $suffix ) ) {
if ( !move $dest, $send ) {
warn getTimeStamp("log") . " >> Move $dest -> $send failed: $!";
} else {
print getTimeStamp("log") . " >> Moved $dest -> $send.\n";
warn getTimeStamp("log")
. " >> Move $dest -> $send failed: $!";
}
} else {
warn getTimeStamp("log") . " >> Put $dest failed ", $ftp->message;
else {
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;
}
}