From 45cf39091fc09be42415e36ad60812611fc332fc Mon Sep 17 00:00:00 2001 From: Alessandro Battilani Date: Sun, 20 Mar 2022 11:22:12 +0100 Subject: [PATCH] prova x nuovo nas --- aruba/UnitCsvRetransmit.pl | 87 ++++++++++++++++++++------------------ 1 file changed, 47 insertions(+), 40 deletions(-) diff --git a/aruba/UnitCsvRetransmit.pl b/aruba/UnitCsvRetransmit.pl index 5b6902e..a01753c 100644 --- a/aruba/UnitCsvRetransmit.pl +++ b/aruba/UnitCsvRetransmit.pl @@ -26,71 +26,78 @@ sub getTimeStamp } my $readingFile; -my $ftpuser = "aseftp"; -my $ftpuser1 = "asega"; +my $ftpuser = "aseftp"; +my $ftpuser1 = "asega"; my $recvOKstr = "OK UPLOAD"; -my $ext = ".csv"; -my $hostname = "160.78.21.55"; -my $username = 'asega'; -my $password = 'mums'; +my $ext = ".csv"; +my $hostname = "160.78.21.55"; +my $username = 'asega'; +my $password = 'mums'; my $lockTS; my $lockfile = '/tmp/retransmit.lock'; -GetOptions( "file=s" => \$readingFile, - "lockts=i" => \$lockTS +GetOptions( + "file=s" => \$readingFile, + "lockts=i" => \$lockTS ) or die("Error in command line arguments\n"); -if (-e $lockfile) { +if ( -e $lockfile ) { my $content; - open(my $fh, '<', $lockfile) or die "cannot open file $lockfile"; + 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); - } + if ( $content != $lockTS ) { + print getTimeStamp("log") + . " >> timestamp mismatch... $content - $lockTS ... Exiting. \n"; + exit(0); + } -} else { - open(FH, '>', $lockfile) or die $!; - print FH $lockTS; - close(FH); +} +else { + open( FH, '>', $lockfile ) or die $!; + print FH $lockTS; + close(FH); } -if (index( $readingFile, 'ZZZZZZ.csv' ) > 0) { - unlink $lockfile; - exit(0); +if ( index( $readingFile, 'ZZZZZZ.csv' ) > 0 ) { + unlink $lockfile; + exit(0); } print getTimeStamp("log") . " >> $readingFile \n"; -my($scriptname, $scriptpath) = fileparse($0); -my($filename, $path, $suffix) = fileparse($readingFile, qr/\.[^.]*/); +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($dmy1, $dmy2, $dmy3, $unit, $dmy4) = split(/\//,$path); +my ( $tool, $trxdate ) = split( /_/, $filename ); +my ( $dmy1, $dmy2, $dmy3, $unit, $dmy4 ) = split( /\//, $path ); print getTimeStamp("log") . " >> Unit $unit - Filename $tool" . "$suffix \n"; -my $ftp = Net::FTP->new($hostname, Timeout => 20, Debug => 0, Passive => 0) - or die getTimeStamp("log") . " >> Cannot connect to $hostname: $@"; -if ($ftp->login($username,$password)) { - if ($ftp->put($readingFile, $tool . $suffix)) { - print getTimeStamp("log") . " >> Put $readingFile completed.\n"; - if ( !move $readingFile, $send) { - warn getTimeStamp("log") . " >> Move $readingFile -> $send failed: $!"; - } else { - print getTimeStamp("log") . " >> Moved $readingFile -> $send.\n"; - } - } else { - die getTimeStamp("log") . " >> Put $readingFile failed ", $ftp->message; - } -} else { - die getTimeStamp("log") . " >> Cannot login ", $ftp->message; +my $ftp = Net::FTP->new( $hostname, Timeout => 20, Debug => 0, Passive => 0 ) + or die getTimeStamp("log") . " >> Cannot connect to $hostname: $@"; +if ( $ftp->login( $username, $password ) ) { + if ( $ftp->put( $readingFile, $tool . $suffix ) ) { + print getTimeStamp("log") . " >> Put $readingFile completed.\n"; + if ( !move $readingFile, $send ) { + warn getTimeStamp("log") + . " >> Move $readingFile -> $send failed: $!"; + } + else { + print getTimeStamp("log") . " >> Moved $readingFile -> $send.\n"; + } + } + else { + die getTimeStamp("log") . " >> Put $readingFile failed ", $ftp->message; + } +} +else { + die getTimeStamp("log") . " >> Cannot login ", $ftp->message; } exit(0);