retransmit mind
This commit is contained in:
55
mind/UnitCsvRetransmit.pl
Normal file → Executable file
55
mind/UnitCsvRetransmit.pl
Normal file → Executable file
@@ -26,66 +26,35 @@ sub getTimeStamp
|
|||||||
}
|
}
|
||||||
|
|
||||||
my $readingFile;
|
my $readingFile;
|
||||||
my $hostname = "160.78.21.55";
|
my $hostname = "80.211.60.65";
|
||||||
my $username = 'asega';
|
my $username = 'asega';
|
||||||
my $password = 'mums';
|
my $password = 'mums';
|
||||||
|
|
||||||
GetOptions( "file=s" => \$readingFile )
|
GetOptions( "file=s" => \$readingFile )
|
||||||
or die("Error in command line arguments\n");
|
or die("Error in command line arguments\n");
|
||||||
|
|
||||||
if ( -e $lockfile ) {
|
(my $file2ASE = $readingFile) =~ s/trx2ASE\///;
|
||||||
my $content;
|
|
||||||
open( my $fh, '<', $lockfile ) or die "cannot open file $lockfile";
|
|
||||||
{
|
|
||||||
local $/;
|
|
||||||
$content = <$fh>;
|
|
||||||
}
|
|
||||||
close($fh);
|
|
||||||
if ( $content != $lockTS ) {
|
|
||||||
print getTimeStamp("log")
|
|
||||||
. " >> timestamp mismatch... $content - $lockTS ... Exiting. \n";
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
print getTimeStamp("log") . " >> $file2ASE \n";
|
||||||
else {
|
|
||||||
open( FH, '>', $lockfile ) or die $!;
|
|
||||||
print FH $lockTS;
|
|
||||||
close(FH);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( index( $readingFile, 'ZZZZZZ.csv' ) > 0 ) {
|
my ( $filename, $path, $suffix ) = fileparse( $file2ASE, qr/\.[^.]*/ );
|
||||||
unlink $lockfile;
|
|
||||||
exit(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
print getTimeStamp("log") . " >> $readingFile \n";
|
|
||||||
|
|
||||||
my ( $scriptname, $scriptpath ) = fileparse($0);
|
|
||||||
my ( $filename, $path, $suffix ) = fileparse( $readingFile, qr/\.[^.]*/ );
|
|
||||||
|
|
||||||
my $send = $readingFile =~ s/received/transmitted/r;
|
|
||||||
|
|
||||||
my ( $tool, $trxdate ) = split( /_/, $filename );
|
my ( $tool, $trxdate ) = split( /_/, $filename );
|
||||||
my ( $dmy1, $dmy2, $dmy3, $unit, $dmy4 ) = split( /\//, $path );
|
my @dirs = split( /\//, $path );
|
||||||
|
|
||||||
print getTimeStamp("log") . " >> Unit $unit - Filename $tool" . "$suffix \n";
|
print getTimeStamp("log") . " >> Unit $dirs[-1] - Filename $tool" . "$suffix \n";
|
||||||
|
|
||||||
my $ftp = Net::FTP->new( $hostname, Timeout => 20, Debug => 0, Passive => 0 )
|
my $ftp = Net::FTP->new( $hostname, Timeout => 20, Debug => 0, Passive => 1 )
|
||||||
or die getTimeStamp("log") . " >> Cannot connect to $hostname: $@";
|
or die getTimeStamp("log") . " >> Cannot connect to $hostname: $@";
|
||||||
if ( $ftp->login( $username, $password ) ) {
|
if ( $ftp->login( $username, $password ) ) {
|
||||||
if ( $ftp->put( $readingFile, $tool . $suffix ) ) {
|
if ( $ftp->put( $file2ASE, $tool . $suffix ) ) {
|
||||||
print getTimeStamp("log") . " >> Put $readingFile completed.\n";
|
print getTimeStamp("log") . " >> Put $file2ASE completed.\n";
|
||||||
if ( !move $readingFile, $send ) {
|
if (-e $readingFile) {
|
||||||
warn getTimeStamp("log")
|
unlink $readingFile ;
|
||||||
. " >> Move $readingFile -> $send failed: $!";
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
print getTimeStamp("log") . " >> Moved $readingFile -> $send.\n";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
die getTimeStamp("log") . " >> Put $readingFile failed ", $ftp->message;
|
die getTimeStamp("log") . " >> Put $file2ASE failed ", $ftp->message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|||||||
Reference in New Issue
Block a user