#!/usr/bin/perl use warnings; use strict; use DBI; use Getopt::Long; use Net::FTP; use File::Basename qw( fileparse ); use List::Util qw( max ); use Data::Dumper qw(Dumper); use Cwd; use MIME::Lite; use Time::Piece; $|++; # Autoflush my ( $filename, $sqlout ); my $username = 'aselar'; my $password = 'laravel'; my $db_lar = 'ase_lar'; my $db_sp = 'ase_lar'; my $server = '85.235.153.201'; my $db_name = "ase_lar"; my $table = "RAWDATACOR"; my ( @CSVData, @sql ); my $outcount = 0; my $outfilenum = 0; my $maxsqllines = 10000; my ( $tool, $toolbatt, $tooltemp, $tooltype, @channels, @NewData, @ain, @din, @nodetype, $GDEventDate ); my $matlab_proxy_ssh = "localhost"; #"80.211.107.201"; my $matlab_proxy_ssh_port = 22; #2222; my $matlab_exec_user = 'asega'; my $matlab_cmd = ""; my $matlab_timestamp = ""; my $ftp_send = 1; my $api_send = 0; my $inoltro_api = 0; my $inoltro_api_url = ""; my $inoltro_api_bearer_token = ""; my $unit_duedate = ""; my $ftp_addrs; my $ftp_user; my $ftp_passwd; my $ftp_parm; my $ftp_filename; my $ftp_target; my $duedate = ''; my ( $unit_id, $unit, $unittype ); my ( $fileDate, $fileTime ); my $matlab_rt = "/usr/local/MATLAB/MATLAB_Runtime/v93"; my $matlab_func_dir = "/usr/local/matlab_func/"; my $matlab_error = ''; my $matlab_timeout = '1800'; my $email_addr = 'andrea.carri@aseltd.eu,alessandro.battilani@gmail.com,alessandro.valletta@aseltd.eu,alberto.sillani@aseltd.eu,majd.saidani@aseltd.eu'; my $from = 'ASE Alert System'; my ( $email_msg, $email_obj ); my $G201_fcheck = 0; my $TLP_fcheck = 0; my $GS1_fcheck = 0; my $D2W_fcheck = 0; my $G301_fcheck = 0; my $CR1000X_fcheck = 0; my $FtpToCustomerCmd = 'SendFtpElabData.pl'; my ( $scriptname, $scriptpath ); my $MatlabErrorPath = "/tmp/"; my $MatlabErrorFilename = $MatlabErrorPath; my @matlabOutputErrorArray; my @errors; my @warnings; my $MatlabErrors = ''; my $MatlabWarnings = ''; my $tool_status = ''; sub uniq { my %seen; grep !$seen{$_}++, @_; } sub getTimeStamp { # parm [ts] => timestamp for filename; log => timestamp for log my $format = "%04d%02d%02d%02d%02d%02d"; my ($p1) = @_; if ( defined $p1 and $p1 eq "log" ) { $format = "%04d%02d%02d %02d:%02d:%02d"; } if ( defined $p1 and $p1 eq "db_ts" ) { $format = "%04d-%02d-%02d %02d:%02d:%02d"; } my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = localtime(time); my $timestamp = sprintf( $format, $year + 1900, $mon + 1, $mday, $hour, $min, $sec ); return $timestamp; } sub writeOutSql { my ($tn) = @_; my $outfile = $sqlout . "_" . $outfilenum++; open SQLOUT, ">", $outfile or die( getTimeStamp("log") . " - pid $$ >> Error: opening output file " . $outfile . ":$!\n" ); print getTimeStamp("log") . " - pid $$ >> file $outfile created\n"; print SQLOUT "/* lock " . $db_name . ".$table table */\nLOCK TABLES " . $db_name . ".$table WRITE;\n"; print SQLOUT "INSERT IGNORE INTO " . $db_name . ".$table\n"; print SQLOUT "(`UnitName`,`ToolNameID`,`NodeNum`,`EventDate`,`EventTime`,`BatLevel`,`Temperature`,\n"; print SQLOUT "`Val0`,`Val1`,`Val2`,`Val3`,`Val4`,`Val5`,`Val6`,`Val7`,`Val8`,`Val9`,`ValA`,`ValB`,`ValC`,`ValD`,`ValE`,`ValF`)\n"; print SQLOUT "VALUES\n"; print SQLOUT @sql; @sql = (); print SQLOUT "/* unlock table */\nUNLOCK TABLES;\n"; close SQLOUT or die( getTimeStamp("log") . " - pid $$ >> Error in closing file " . $outfile . "\n" ); my @args = ( "mysql", "--login-path=asepath", "-e source " . $outfile ); system(@args) == 0 or die( getTimeStamp("log") . " - pid $$ >> system @args failed: $?\n" ); print getTimeStamp("log") . " - pid $$ >> file $outfile loaded into DB\n"; unlink $outfile; return; } sub modifyAndWriteOutSql { my ($tn) = @_; my $outfile2 = $sqlout . "_" . $outfilenum++; open SQLOUT, ">", $outfile2 or die( getTimeStamp("log") . " - pid $$ >> Error: opening output file " . $outfile2 . ":$!\n" ); print getTimeStamp("log") . " - pid $$ >> file $outfile2 IPI created\n"; print SQLOUT "/* lock " . $db_name . ".$table table */\nLOCK TABLES " . $db_name . ".$table WRITE;\n"; print SQLOUT "INSERT IGNORE INTO " . $db_name . ".$table\n"; print SQLOUT "(`UnitName`,`ToolNameID`,`NodeNum`,`EventDate`,`EventTime`,`BatLevel`,`Temperature`,\n"; print SQLOUT "`Val0`,`Val1`,`Val2`,`Val3`,`Val4`,`Val5`,`Val6`,`Val7`,`Val8`,`Val9`,`ValA`,`ValB`,`ValC`,`ValD`,`ValE`,`ValF`)\n"; print SQLOUT "VALUES\n"; foreach my $row (@sql) { my @row_values = split /','/, $row; if ($row_values[0] eq "('ID0070" && $row_values[1] eq 'DT0111') { $row_values[0] = "('ID0070"; $row_values[1] = 'DT0111 IPI'; } elsif ($row_values[0] eq "('ID0071" && $row_values[1] eq 'DT0112') { $row_values[0] = "('ID0071"; $row_values[1] = 'DT0112 IPI'; } elsif ($row_values[0] eq "('ID0072" && $row_values[1] eq 'DT0113') { $row_values[0] = "('ID0072"; $row_values[1] = 'DT0113 IPI'; } elsif ($row_values[0] eq "('ID0073" && $row_values[1] eq 'DT0114') { $row_values[0] = "('ID0073"; $row_values[1] = 'DT0114 IPI'; } elsif ($row_values[0] eq "('ID0273" && $row_values[1] eq 'DT0001') { $row_values[0] = "('ID0273"; $row_values[1] = 'DT0002'; } elsif ($row_values[0] eq "('ID00279" && $row_values[1] eq 'DT0008') { $row_values[0] = "('ID0279"; $row_values[1] = 'DT0008'; } my $modified_row_string = "" . join("','", @row_values) . "\n"; print SQLOUT $modified_row_string; #print getTimeStamp("log") . " - pid $$ >> row IPI[".$row_values[0]." ".$row_values[1]."] $modified_row_string\n"; } print SQLOUT "/* unlock table */\nUNLOCK TABLES;\n"; close SQLOUT or die( getTimeStamp("log") . " - pid $$ >> Error in closing file " . $outfile2 . "\n" ); my @args = ( "mysql", "--login-path=asepath", "-e source " . $outfile2 ); system(@args) == 0 or die( getTimeStamp("log") . " - pid $$ >> system @args failed: $?\n" ); print getTimeStamp("log") . " - pid $$ >> file $outfile2 IPI loaded into DB\n"; unlink $outfile2; return; } sub matlabCalc { $matlab_timestamp = getTimeStamp("db_ts"); print getTimeStamp("log") . " - pid $$ >> $unit - $tool MatLab calc started...\n"; if ( $matlab_cmd =~ /_lnx$/ ) { $matlab_cmd = './run_' . $matlab_cmd . '.sh'; $MatlabErrorFilename .= "${unit}${tool}_output_error.txt"; #print $ENV{"HOME"} . "\n"; $ENV{"HOME"} = "/" . $ENV{"HOME"}; chdir($matlab_func_dir) or die "cannot change: $!\n"; print getTimeStamp("log") . " - pid $$ >> current dir: $matlab_func_dir\n"; my $args = "timeout $matlab_timeout $matlab_cmd $matlab_rt $unit $tool"; if ( system($args) != 0 ) { my $argscat = "cd $MatlabErrorPath; cat _${unit}_${tool}*_\*_output_error.txt > ${unit}${tool}_output_error.txt"; system($argscat); open( my $fh, '<', $MatlabErrorFilename ) or warn print getTimeStamp("log") . " - pid $$ >> Cannot open Matlab output error file: ${MatlabErrorFilename}\n"; { chomp( @matlabOutputErrorArray = <$fh> ); } close($fh); @matlabOutputErrorArray = grep( /\S/, @matlabOutputErrorArray ); @errors = grep( /^Error/, @matlabOutputErrorArray ); @warnings = grep( !/^Error/, @matlabOutputErrorArray ); $MatlabErrors = join( "
", @errors ); $MatlabWarnings = join( "
", uniq(@warnings) ); my $exit_value = $? >> 8; if ( $exit_value == 124 ) { print getTimeStamp("log") . " - pid $$ >> system $args excessive duration: killed after $matlab_timeout seconds\n"; $matlab_error = "Matlab elab excessive duration: killed after $matlab_timeout seconds"; } else { print getTimeStamp("log") . " - pid $$ >> system $args failed: return code $exit_value - $?\n"; $matlab_error = "Matlab elab failed: $exit_value - $?"; } makeEmailMsg(); emailSend(); print getTimeStamp("log") . " - pid $$ >> Execution ended.\n"; exit(1); } } print getTimeStamp("log") . " - pid $$ >> $unit - $tool MatLab calc executed.\n"; return; } sub trxelab { my $user = getpwuid($>); my $ftpcmd = "$scriptpath$FtpToCustomerCmd -m \"$matlab_timestamp\" -u $unit -t $tool >> /home/$user/log/loadcsvdata.log 2>&1"; print getTimeStamp("log") . " - pid $$ >> Fork FTP command to set GID mysql: $ftpcmd.\n"; unless ( fork() ) { exec( '/usr/bin/sg', 'mysql', "$ftpcmd" ); exit(0); } } sub trxelabApi { print getTimeStamp("log") . " - pid $$ >> DEBUG inoltro ELAB API: /home/battilo/scripts/inoltroViaApiElab.py $matlab_timestamp $unit $tool $inoltro_api_url $inoltro_api_bearer_token\n"; unless ( fork() ) { exec("/home/battilo/scripts/inoltroViaApiElab.py \"$matlab_timestamp\" \"$unit\" \"$tool\" \"$inoltro_api_url\" \"$inoltro_api_bearer_token\" >> /home/asega/log/logInoltroViaApiElab.log 2>&1"); exit(0); } } sub getNodesType { my $dbh = DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password ) or die getTimeStamp("log") . " - pid $$ >> Could not connect to database: $DBI::errstr"; my $sth = $dbh->prepare('select t.name as name, n.seq as seq, n.num as num, n.channels as channels, y.type as type, n.ain as ain, n.din as din from nodes as n inner join tools as t on t.id = n.tool_id inner join units as u on u.id = t.unit_id inner join nodetypes as y on n.nodetype_id = y.id where y.type not in (\'Anchor Link\', \'None\') and t.name = "' . $tool . '" and u.name = "' . $unit . '" order by 3;' ) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr"; $sth->execute(); print getTimeStamp("log") . " - pid $$ >> $unit - $tool: " . $sth->rows . " rows selected to get node type/Ain/Din/channels.\n"; if ( $sth->rows eq 0 ) { print getTimeStamp("log") . " - pid $$ >> Node/Channels/Ain/Din not defined.\n"; print getTimeStamp("log") . " - pid $$ >> Execution ended.\n"; exit; } else { my $row = 0; while ( my $results = $sth->fetchrow_hashref ) { $channels[$row] = $results->{'channels'}; $nodetype[$row] = $results->{'type'}; $ain[$row] = $results->{'ain'}; $din[ $row++ ] = $results->{'din'}; } } $sth->finish; # Disconnect $dbh->disconnect; return; } sub getUdbPwd { my $dbh = DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password ) or die getTimeStamp("log") . " - pid $$ >> Could not connect to database: $DBI::errstr"; my $sth = $dbh->prepare( "SELECT db_user, db_pwd FROM ase_lar.companies where db_name = '" . $db_name . "';" ) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr"; $sth->execute(); if ( $sth->rows eq 0 ) { #$password = "laravel"; #$username = "ase_lar"; die getTimeStamp("log") . " - pid $$ >> No password selected.\n"; } else { my $results = $sth->fetchrow_hashref; $password = $results->{'db_pwd'}; $username = $results->{'db_user'}; } $sth->finish; # Disconnect $dbh->disconnect; return; } sub getMatlabCmd { my $dbh = DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password ) or die getTimeStamp("log") . " - pid $$ >> Could not connect to database: $DBI::errstr"; my $sth = $dbh->prepare('select m.matcall, t.ftp_send , t.unit_id, s.`desc` as statustools, t.api_send, u.inoltro_api, u.inoltro_api_url, u.inoltro_api_bearer_token, IFNULL(u.duedate, "") as duedate from matfuncs as m inner join tools as t on t.matfunc = m.id inner join units as u on u.id = t.unit_id inner join statustools as s on t.statustool_id = s.id where t.name = "' . $tool . '" and u.name = "' . $unit . '";' ) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr"; $sth->execute(); if ( $sth->rows eq 0 ) { die getTimeStamp("log") . " - pid $$ >> No tool's matlab function selected.\n"; } else { while ( my $results = $sth->fetchrow_hashref ) { $matlab_cmd = $results->{'matcall'}; $ftp_send = $results->{'ftp_send'}; $unit_id = $results->{'unit_id'}; $tool_status = $results->{'statustools'}; $api_send = $results->{'api_send'}; $inoltro_api = $results->{'inoltro_api'}; $inoltro_api_url = $results->{'inoltro_api_url'}; $inoltro_api_bearer_token = $results->{'inoltro_api_bearer_token'}; $unit_duedate = $results->{'duedate'}; } } $sth->finish; # Disconnect $dbh->disconnect; return; } sub makeEmailMsg { $email_msg = <<"END_MSG"; Alert from ASE
ASE

Alert from ASE:

Matlab function $matlab_cmd failed on unit => $unit - tool => $tool

$matlab_error

$MatlabErrors
$MatlabWarnings
END_MSG } sub emailSend { $email_obj = 'Matlab error on unit ' . $unit . ' - tool ' . $tool; #print getTimeStamp("log") . " - pid $$ >> $email_msg\n"; #print getTimeStamp("log") . " - pid $$ >> $email_obj\n"; my $msg = MIME::Lite->new( From => $from, To => $email_addr, Subject => $email_obj, Data => $email_msg ); #AuthUser => "alert\@aseltd.eu", #AuthPass => "Ase#2013!20\@bat", $msg->attr( "content-type" => "text/html" ); if ($msg->send('smtp', "smtp.aseltd.eu", AuthUser => "alert\@aseltd.eu", AuthPass => "Ase#2013!20\@bat", Port => 587, Debug => 0)) { print getTimeStamp("log") . " - pid $$ >> $email_obj\n"; print getTimeStamp("log") . " - pid $$ >> Mail sent to: $email_addr.\n"; } else { print getTimeStamp("log") . " - pid $$ >> Error in sending mail to: $email_addr.\n"; } } my $starttime = getTimeStamp("log"); print "$starttime - pid $$ >> Start execution.\n"; GetOptions( "filename=s" => \$filename, "sqlout=s" => \$sqlout, "dbname=s" => \$db_name ) or die("Error in command line arguments\n"); ####### EDIT FILE PER ID0013 ########## open FILE, $filename or die( "Error: opening input file " . $filename . "\n" ); my ( $filecsvname, $path, $suffix ) = fileparse( $filename, qr/\.[^.]*/ ); if ( $filecsvname =~ m/^(\d\d_\d\d\d\d_|)(DT\d\d\d\d|LOC\d.*|GD\d*)_\d*$/i ) { my @lines = ; # Read all lines of the file into an array close(FILE) or die "Error closing1 $filename: $!"; # Close the file after reading all lines ( $fileDate, $fileTime ) = split( /\s/, $lines[0] ); # Assuming first line is File Creation Date ( $unittype, $unit ) = split( /\s/, uc $lines[1] ); # Extract unit from second line $unit =~ s/;+$//; # Clean up the unit string if ($unit eq "ID0013") { # Process only for unit "ID0013" my $section_count = 0; my $keep = 0; my @filtered_lines; my @current_section; # Temporarily store lines of the current section for my $line (@lines) { # Identify the start of a new section if ($line =~ /^File Creation Date:/) { $section_count++; # If previous section was marked to be kept, store it push @filtered_lines, @current_section if $keep; # Reset section data @current_section = (); $keep = 0; } # Always store the current section's lines in a buffer push @current_section, $line; # If the SD path contains "/modb/", mark this section to be kept if ($line =~ /SD path: .*?\/modb\//) { $keep = 1; } } # Ensure the last section is processed push @filtered_lines, @current_section if $keep; # Only modify the file if there are 2 or more sections if ($section_count > 1) { print getTimeStamp("log") . " - pid $$ >> (EDIT PER ID0013) Detected multiple sections ($section_count). Keeping only /modb/ section.\n"; # Rewrite the file with filtered content (only the relevant section) open FILE, '>', $filename or die "Error: (EDIT PER ID0013) opening file for writing $filename: $!\n"; print FILE @filtered_lines; close(FILE) or die "Error closing2 $filename: $!"; print getTimeStamp("log") . " - pid $$ >> File updated, only /modb/ section retained for ID0013.\n"; } else { print getTimeStamp("log") . " - pid $$ >> Only one section found, no changes made to file.\n"; } } else { print getTimeStamp("log") . " - pid $$ >> Unit is not ID0013, continue normal processing.\n"; } } else { close(FILE) or die "Error closing3 $filename: $!"; } ######### NORMAL PROCESSING ########### open FILE, $filename or die( "Error: opening input file " . $filename . "\n" ); ( $scriptname, $scriptpath ) = fileparse($0); if ( $db_name ne 'asega' ) { $db_name =~ s/aseu/dbn/; #$db_name = "ase_lar"; $db_sp = $db_name; #$db_sp = "ase_lar"; getUdbPwd(); #die getTimeStamp("log") . " - pid $$ >> debug dbname:".$db_name."\n"; $db_lar = $db_name; #$db_lar = "ase_lar"; } else { $db_name = 'ase_lar'; } ( $filecsvname, $path, $suffix ) = fileparse( $filename, qr/\.[^.]*/ ); if ( $filecsvname =~ m/^(\d\d_\d\d\d\d_|)(DT\d\d\d\d|LOC\d.*|GD\d*)_\d*$/i ) { ( $fileDate, $fileTime ) = split( /\s/, ); ( $unittype, $unit ) = split( /\s/, uc ); $unit =~ s/;+$//; if ($unit eq "ID0013") {#non mette dati e non fa elab se dentro i dt della id0013 c'è /mums/ nel path sd my $offset_after_second_line = tell(FILE);#salva la posizione my @linesTmp = ; print getTimeStamp("log") . " - pid $$ >> DEBUG ID0013 - $linesTmp[3]\n"; #my ( $unused_iptext, $unused_ip ) = split( /\s/, $linesTmp[0] ); #my ( $unused_subnettext, $unused_subnet ) = split( /\s/, $linesTmp[1] ); #my ( $unused_gatewaytext, $unused_gatewayip ) = split( /\s/, $linesTmp[2] ); my ( $unused_sdtext, $unused_pathtext, $sd_path ) = split( /\s/, $linesTmp[3] ); if($sd_path =~ /\/mums\//){ print getTimeStamp("log") . " - pid $$ >> in path SD there is /mums/ for unit=$unit, sd_path=$sd_path EXITING the script\n"; close FILE; exit; # Exit the script successfully } seek(FILE, $offset_after_second_line, 0);#torna alla posizione dopo la seconda riga letta } } elsif ( $filecsvname =~ m/^G201_ID\d\d\d\d_DT\d\d\d\d_\d*_\d*$/i ) { my @strings = $filecsvname =~ /(.{1,4})_(.{1,6})_(.{1,6})_(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2}).*/; $unittype = $strings[0]; $unit = $strings[1]; $tool = $strings[2]; $fileDate = $strings[3] . "/" . $strings[4] . "/" . $strings[5]; $fileTime = $strings[6] . ":" . $strings[7] . ":" . $strings[8]; $tooltype = 'MUX'; } elsif ( $filecsvname =~ m/^G201_ID\d\d\d\d_DT\d\d\d\d\d*_\d*$/i ) { my @strings = $filecsvname =~ /(.{1,4})_(.{1,6})_(.{1,6})(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2}).*/; $unittype = $strings[0]; $unit = $strings[1]; $tool = $strings[2]; $fileDate = $strings[3] . "/" . $strings[4] . "/" . $strings[5]; $fileTime = $strings[6] . ":" . $strings[7] . ":" . $strings[8]; $tooltype = 'MUX'; } elsif ( $filecsvname =~ m/^TLP_ID\d\d\d\d_DT\d\d\d\d_\d*_\d*$/i ) { my @strings = $filecsvname =~ /(.{1,4})_(.{1,6})_(.{1,6})_(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2}).*/; $unittype = $strings[0]; $unit = $strings[1]; $tool = $strings[2]; $fileDate = $strings[3] . "/" . $strings[4] . "/" . $strings[5]; $fileTime = $strings[6] . ":" . $strings[7] . ":" . $strings[8]; $tooltype = 'TLP'; } elsif ( $filecsvname =~ m/^TLP_ID\d\d\d\d_DT\d\d\d\d\d*_\d*$/i ) { my @strings = $filecsvname =~ /(.{1,4})_(.{1,6})_(.{1,6})(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2}).*/; $unittype = $strings[0]; $unit = $strings[1]; $tool = $strings[2]; $fileDate = $strings[3] . "/" . $strings[4] . "/" . $strings[5]; $fileTime = $strings[6] . ":" . $strings[7] . ":" . $strings[8]; $tooltype = 'TLP'; } elsif ( $filecsvname =~ m/^GS1_ID\d\d\d\d_DT\d\d\d\d_\d*_\d*$/i ) { my @strings = $filecsvname =~ /(.{1,4})_(.{1,6})_(.{1,6})_(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2}).*/; $unittype = $strings[0]; $unit = $strings[1]; $tool = $strings[2]; $fileDate = $strings[3] . "/" . $strings[4] . "/" . $strings[5]; $fileTime = $strings[6] . ":" . $strings[7] . ":" . $strings[8]; $tooltype = 'GS1'; if($unit eq "ID0273" && $tool eq "DT0001"){ $tool = "DT0002"; } } elsif ( $filecsvname =~ m/^GS1_ID\d\d\d\d_DT\d\d\d\d\d*_\d*$/i ) { my @strings = $filecsvname =~ /(.{1,4})_(.{1,6})_(.{1,6})(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2}).*/; $unittype = $strings[0]; $unit = $strings[1]; $tool = $strings[2]; $fileDate = $strings[3] . "/" . $strings[4] . "/" . $strings[5]; $fileTime = $strings[6] . ":" . $strings[7] . ":" . $strings[8]; $tooltype = 'GS1'; if($unit eq "ID0273" && $tool eq "DT0001"){ $tool = "DT0002"; } } elsif ( $filecsvname =~ m/^GS1_ID\d\d\d\d\d_DT\d\d\d\d_\d*_\d*$/i ) {#per id con 1 cifra in + my @strings = $filecsvname =~ /(.{1,4})_(.{1,7})_(.{1,6})_(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2}).*/; $unittype = $strings[0]; $unit = $strings[1]; $tool = $strings[2]; $fileDate = $strings[3] . "/" . $strings[4] . "/" . $strings[5]; $fileTime = $strings[6] . ":" . $strings[7] . ":" . $strings[8]; $tooltype = 'GS1'; if($unit eq "ID00279" && $tool eq "DT0008"){ $unit = "ID0279"; } } elsif ( $filecsvname =~ m/^GS1_ID\d\d\d\d\d_DT\d\d\d\d\d*_\d*$/i ) {#per id con 1 cifra in + my @strings = $filecsvname =~ /(.{1,4})_(.{1,7})_(.{1,6})(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2}).*/; $unittype = $strings[0]; $unit = $strings[1]; $tool = $strings[2]; $fileDate = $strings[3] . "/" . $strings[4] . "/" . $strings[5]; $fileTime = $strings[6] . ":" . $strings[7] . ":" . $strings[8]; $tooltype = 'GS1'; if($unit eq "ID00279" && $tool eq "DT0008"){ $unit = "ID0279"; } } elsif ( $filecsvname =~ m/^D2W_ID\d\d\d\d_DT\d\d\d\d_\d*$/i ) { my @strings = $filecsvname =~ /(.{1,3})_(.{1,6})_(.{1,6}).*/; $unittype = $strings[0]; $unit = $strings[1]; $tool = $strings[2]; $tooltype = 'D2W'; } elsif ( $filecsvname =~ m/^CR1000X_ID\d\d\d\d_DT\d\d\d\d_\d*$/i ) { my @strings = $filecsvname =~ /(.{1,7})_(.{1,6})_(.{1,6}).*/; $unittype = $strings[0]; $unit = $strings[1]; $tool = $strings[2]; $tooltype = 'CR1000X'; } elsif ( $filecsvname =~ m/^Hortus_ID\d\d\d\d_DT\d\d\d\d_\d*_\d*$/i ) { my @strings = $filecsvname =~ /(.{1,6})_(.{1,6})_(.{1,6})_(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2})_(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2}).*/; $unittype = $strings[0]; $unit = $strings[1]; $tool = $strings[2]; $fileDate = $strings[3] . "/" . $strings[4] . "/" . $strings[5]; $fileTime = $strings[6] . ":" . $strings[7] . ":" . $strings[8]; $tooltype = 'CR1000X'; } elsif ( $filecsvname =~ m/^(\d*_|)(G301_ID\d\d\d\d_DT\d\d\d\d_\d*)$/i ) { my $filecsvname_clean = substr( $filecsvname, index( $filecsvname, "G301" ) ); my @strings = $filecsvname_clean =~ /(.{1,4})_(.{1,6})_(.{1,6}).*/; $unittype = $strings[0]; $unit = $strings[1]; $tool = $strings[2]; $tooltype = 'G301'; } #print getTimeStamp("log") . " - pid $$ >> DEBUG SONO QUA!!!!!\n"; while ( my $line = ) { #if ( $line =~ m/\A [[:ascii:]]* \Z/xms ) { #print getTimeStamp("log") . " - pid $$ >> DEBUG $unittype , $tooltype\n"; #print getTimeStamp("log") . " - pid $$ >> DEBUG !!!!!!! $line\n"; if ( $line !~ /\x00/ ) { $line =~ tr /\,/\;/ if ( $line =~ m/^\"\d\d\d\d.*/i ); #CR1000X $line =~ s/\"//g; #print getTimeStamp("log") . " - pid $$ >> DEBUG line: $line\n"; my ( $first, $NodeData ) = split( /;/, $line, 2 ); #print getTimeStamp("log") . " - pid $$ >> DEBUG nodedata: $NodeData\n"; if ( defined $first and ( $first ne '' ) ) { #print getTimeStamp("log") . " - pid $$ >> DEBUG first:" .$first ."\n"; $first =~ s/;+$//; $first =~ tr /\-/\//; #print getTimeStamp("log") . " - pid $$ >> DEBUG first: $first\n"; if ( ( $NodeData =~ m/^;+/ ) ) {#se bat e/o temp sono vuoti metto -1 #print getTimeStamp("log") . " - pid $$ >> DEBUG nodedata: $NodeData\n"; my (@batTempVuotiSplit) = split( /;/, $NodeData ); if($batTempVuotiSplit[0] eq "" || $batTempVuotiSplit[1] eq ""){ if($batTempVuotiSplit[0] eq ""){#bat $batTempVuotiSplit[0] = "-1"; } if($batTempVuotiSplit[1] eq ""){#temp $batTempVuotiSplit[1] = "-273"; } $NodeData = join(';', @batTempVuotiSplit); #print getTimeStamp("log") . " - pid $$ >> DEBUG nodedata modificato: $NodeData\n"; } } if ( !defined $NodeData or ( $NodeData =~ m/^;+/ ) ) { #print getTimeStamp("log") . " - pid $$ >> DEBUG NodeData3:" .$NodeData."\n"; my @info = ( split( /[\/,\.]/, $first ) ); if ( defined $info[3] && $info[3] =~ m/^DT\d\d\d\d$/i ) { #G801 $tool = uc $info[3]; $tooltype = uc $info[2]; print getTimeStamp("log") . " - pid $$ >> Found $tooltype tool name: $tool\n"; getNodesType(); } elsif ( defined $info[5] && $info[5] =~ m/^DT\d\d\d\d$/i ) { #G802 $tool = uc $info[5]; $tooltype = uc $info[4]; print getTimeStamp("log") . " - pid $$ >> Found $tooltype tool name: $tool\n"; getNodesType(); } elsif ( defined $info[2] && $info[2] =~ m/^LOC\d*$/i ) { #G801 $tool = uc $info[2]; $tooltype = 'LOC'; print getTimeStamp("log") . " - pid $$ >> Found $tooltype tool name: $tool\n"; getNodesType(); } elsif ( defined $info[4] && $info[4] =~ m/^LOC\d*$/i ) { #G802 $tool = uc $info[4]; $tooltype = 'LOC'; print getTimeStamp("log") . " - pid $$ >> Found $tooltype tool name: $tool\n"; getNodesType(); } elsif ( defined $info[3] && $info[3] =~ m/^GD\d*$/i ) { $tool = uc $info[3]; $tooltype = 'GD'; print getTimeStamp("log") . " - pid $$ >> Found $tooltype tool name: $tool\n"; } elsif($unittype eq 'Hortus' and $tooltype eq 'CR1000X'){ #Hortus CR1000X print getTimeStamp("log") . " - pid $$ >> Found Hortus $tooltype tool name: $tool\n"; getNodesType(); } } else { $NodeData =~ s/\x0d{0,1}\x0a\Z//s; $NodeData =~ s/;+$//; #$NodeData =~ s/\r\n\z//; if ( $unittype eq 'G201' and $G201_fcheck eq 0 ) { print getTimeStamp("log") . " - pid $$ >> Found $tooltype tool name: $tool\n"; getNodesType(); $G201_fcheck = 1; } if ( $unittype eq 'TLP' and $TLP_fcheck eq 0 ) { print getTimeStamp("log") . " - pid $$ >> Found $tooltype tool name: $tool\n"; getNodesType(); $TLP_fcheck = 1; } if ( $unittype eq 'GS1' and $GS1_fcheck eq 0 ) { print getTimeStamp("log") . " - pid $$ >> Found $tooltype tool name: $tool\n"; getNodesType(); $GS1_fcheck = 1; } if ( $unittype eq 'D2W' and $D2W_fcheck eq 0 ) { print getTimeStamp("log") . " - pid $$ >> Found $tooltype tool name: $tool\n"; getNodesType(); $D2W_fcheck = 1; } if ( $unittype eq 'CR1000X' and $CR1000X_fcheck eq 0 ) { print getTimeStamp("log") . " - pid $$ >> Found $tooltype tool name: $tool\n"; getNodesType(); $CR1000X_fcheck = 1; } if ( $unittype eq 'G301' and $G301_fcheck eq 0 ) { print getTimeStamp("log") . " - pid $$ >> Found $tooltype tool name: $tool\n"; getNodesType(); $G301_fcheck = 1; } if($unittype eq 'Hortus' and $tooltype eq 'CR1000X'){ #Hortus CR1000X print getTimeStamp("log") . " - pid $$ >> Found Hortus $tooltype tool name: $tool\n"; getNodesType(); } if ( $tooltype eq "MUX" or $tooltype eq "D2W" or $tooltype eq "G301" ) { #$NodeData =~ s/Dis\./N\/A/g; @NewData = grep /\S/, split( /\||;/, $NodeData ); if ( scalar(@NewData) != 0 ) { my $idx = 0; $CSVData[ $idx++ ] = join( ';', splice( @NewData, 0, 2 ) ); foreach my $ch (@channels) { $CSVData[ $idx++ ] = join( ';', splice( @NewData, 0, $ch ) ); } } } elsif ( $tooltype eq "CR1000X" ) { # può essere tolto per attivarlo @CSVData = split( /\|/, $NodeData ); } elsif ( $tooltype eq "MUSA" ) { #$NodeData =~ s/Dis\./N\/A/g; my @tmpData = grep /\S/, split( /\||;/, $NodeData ); my $tmpBatt = shift @tmpData; @NewData = ( $tmpBatt, $tmpData[0], @tmpData ); my $idx = 0; $CSVData[ $idx++ ] = join( ';', splice( @NewData, 0, 2 ) ); foreach my $ch (@channels) { $CSVData[ $idx++ ] = join( ';', splice( @NewData, 0, $ch ) ); } #print Dumper \@CSVData; #print Dumper \@channels; #print Dumper \@din; } elsif ( $tooltype eq "LOC" ) { my ( $Vbat, $Tmod, $Ain1, $Ain2, $Din1, $Din2 ) = split( /;/, $NodeData ); my $idx = 0; $CSVData[ $idx++ ] = $Vbat . ";" . $Tmod; my $used_din = 0; my $used_ain = 0; for my $i ( 0 .. $#din ) { #print getTimeStamp("log") . " - pid $$ >> DEBUG LOC din: ". $din[$i] ." ain1:".$Ain1." ain2:".$Ain2." din1:". $Din1. " din2:". $Din2. "\n"; #print getTimeStamp("log") . " - pid $$ >> DEBUG LOC ain: ". $ain[$i] ." ain1:".$Ain1." ain2:".$Ain2." din1:". $Din1. " din2:". $Din2. "\n"; if ( $din[$i] eq 1 ) { if ( $used_din eq 0 ) { $CSVData[ $idx++ ] = $Din1; $used_din = 1; } else { $CSVData[ $idx++ ] = $Din2; } } elsif ( $ain[$i] eq 1 ) { if ( $used_ain eq 0 ) { $CSVData[ $idx++ ] = $Ain1; $used_ain = 1; } else { $CSVData[ $idx++ ] = $Ain2; } } elsif ( $din[$i] eq 2 ) { #$CSVData[ $idx++ ] = $Din1 . ";" . $Din2; #$CSVData[ $idx++ ] = $Din1; $CSVData[ $idx++ ] = $Din2; } elsif ( $ain[$i] eq 2 ) { #$CSVData[ $idx++ ] = $Ain1 . ";" . $Ain2; #$CSVData[ $idx++ ] = $Ain1; $CSVData[ $idx++ ] = $Ain2; } else { $CSVData[ $idx++ ] = "N/A"; } } } elsif ( $tooltype eq "GD" ) { my ( $div, $Vbat, $Tmod ) = split( /;/, $NodeData ); $CSVData[0] = $Vbat . ";" . $Tmod; my ( $y, $m, $d, $t ) = split( /[\s\/]/, $first ); my ( $h, $min, $sec ) = split( /:/, $t ); $GDEventDate = $y . '-' . $m . '-' . $d; $CSVData[1] = "DT" . substr( $tool, 2, 4 ) . ';' . $h . ':' . ( $min - 1 ) . ';' . $h . ':' . ( $min + 1 ); } elsif( $tooltype eq "TLP") { @NewData = grep /\S/, split( /\||;/, $NodeData ); if ( scalar(@NewData) != 0 ) { my $idx = 0; my $batTempPressione = join( ';', splice( @NewData, 0, 3 ) );#3 valori togliere il terzo e metterlo nell'ultimo nodo che dovrebbe essere sempre vuoto my @batTempPressioneParts = split(/;/, $batTempPressione); $CSVData[ $idx++ ] = join( ';', @batTempPressioneParts[0,1] ); #print "inzio\n"; #print $idx++."\n"; #print join( ';', @batTempPressioneParts[0,1] )."\n"; #print "inizio for\n"; foreach my $ch (@channels) { $CSVData[ $idx++ ] = join( ';', splice( @NewData, 0, $ch ) ); #print $idx++."\n"; #print "canale: $ch\n"; #print join( ';', splice( @NewData, 0, $ch ) )."\n"; #print "fine giro\n"; } $CSVData[ $idx ] = $batTempPressioneParts[2]; #print $batTempPressioneParts[2]; } } elsif( $tooltype eq "GS1") { @NewData = grep /\S/, split( /\||;/, $NodeData ); if ( scalar(@NewData) != 0 ) { my $idx = 0; my $batTempPressione = join( ';', splice( @NewData, 0, 3 ) );#3 valori togliere il terzo e metterlo nell'ultimo nodo che dovrebbe essere sempre vuoto my @batTempPressioneParts = split(/;/, $batTempPressione); $CSVData[ $idx++ ] = join( ';', @batTempPressioneParts[0,1] ); #print "inzio\n"; #print $idx++."\n"; #print join( ';', @batTempPressioneParts[0,1] )."\n"; #print "inizio for\n"; foreach my $ch (@channels) { $CSVData[ $idx++ ] = join( ';', splice( @NewData, 0, $ch ) ); #print $idx++."\n"; #print "canale: $ch\n"; #print join( ';', splice( @NewData, 0, $ch ) )."\n"; #print "fine giro\n"; } $CSVData[ $idx ] = $batTempPressioneParts[2]; #print $batTempPressioneParts[2]; } } else { @CSVData = split( /\|/, $NodeData ); } my $nodenum = 0; foreach (@CSVData) { #print getTimeStamp("log") . " - pid $$ >> CSVdata: ". $_ ."\n"; if($_ ne ""){ $sql[ ( $outcount % $maxsqllines ) ] = ""; my (@data) = grep { /\S/ } split( /\;/, $_ ); if ( $nodenum eq 0 ) { #print getTimeStamp("log") . " - pid $$ >> DEBUG batt: ". $data[0] . " " . $data[1] ."\n"; $toolbatt = $data[0]; $tooltemp = $data[1]; } else { my ( $y, $m, $d, $t ) = split( /[\s\/]/, $first ); if ( length($y) != 4 ) { # G201/G301 con la data invertita my $w = $y; $y = $d; $m = sprintf( '%02d', $m ); $d = sprintf( '%02d', $w ); } #print getTimeStamp("log") . " - pid $$ >> DEBUG data $y-$m-$d\n"; foreach (@data) { if ( $sql[ ( $outcount % $maxsqllines ) ] eq "" ) { $sql[ ( $outcount % $maxsqllines ) ] = "('$unit','$tool','$nodenum','$y-$m-$d','$t','$toolbatt','$tooltemp'"; } $sql[ ( $outcount % $maxsqllines ) ] .= ",'" . $_ . "'"; } my $InsCompl = ",NULL" x ( 15 - $#data ); $sql[ ( $outcount % $maxsqllines ) ] .= $InsCompl . ")"; if ( ++$outcount % $maxsqllines eq 0 ) { $sql[ ( $outcount % $maxsqllines ) - 1 ] .= ";\n"; my $tool_status2 = ""; my $dbh2 = DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password ) or die getTimeStamp("log") . " - pid $$ >> Could not connect to database: $DBI::errstr"; my $sth2 = $dbh2->prepare( 'select m.matcall, t.ftp_send , t.unit_id, s.`desc` as statustools from matfuncs as m inner join tools as t on t.matfunc = m.id inner join units as u on u.id = t.unit_id inner join statustools as s on t.statustool_id = s.id where t.name = "' . $tool . '" and u.name = "' . $unit . '";' ) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr"; $sth2->execute(); if ( $sth2->rows eq 0 ) { die getTimeStamp("log") . " - pid $$ >> Check tool status later - No tool's matlab function selected.\n"; } else { while ( my $results2 = $sth2->fetchrow_hashref ) { $tool_status2 = $results2->{'statustools'}; } } $sth2->finish; # Disconnect $dbh2->disconnect; if($tool_status2 eq "Test"){ print getTimeStamp("log") . " - pid $$ >> tool status: $tool_status2 nothing to do.\n"; }else{ if(($unit eq "ID0070" && $tool eq "DT0111") || ($unit eq "ID0071" && $tool eq "DT0112") || ($unit eq "ID0072" && $tool eq "DT0113") || ($unit eq "ID0073" && $tool eq "DT0114") || ($unit eq "ID0273" && $tool eq "DT0001") || ($unit eq "ID0279" && $tool eq "DT0008")){ modifyAndWriteOutSql($tool); } writeOutSql($tool); } } else { $sql[ ( $outcount % $maxsqllines ) - 1 ] .= ",\n"; } } $nodenum++; } } } } } } close FILE; $sql[ ( $outcount % $maxsqllines ) - 1 ] =~ s/,$/;/g; my $tool_status3 = ""; #FTP INOLTRO RAW my $inoltro_ftp_raw = 0; my $ftp_send_raw = ""; my $ftp_mode_raw = ""; my $ftp_addrs_raw = ""; my $ftp_user_raw = ""; my $ftp_passwd_raw = ""; my $ftp_filename_raw = ""; my $ftp_target_raw = ""; #api raw my $inoltro_api_raw = 0; my $inoltro_api_url_raw = ""; my $inoltro_api_bearer_token_raw = ""; my $api_send_raw = 0; # my $dbh3 = DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password ) or die getTimeStamp("log") . " - pid $$ >> Could not connect to database: $DBI::errstr"; my $sth3 = $dbh3->prepare( 'select m.matcall, t.ftp_send_raw, IFNULL(u.ftp_mode_raw, "") as ftp_mode_raw, IFNULL(u.ftp_addrs_raw, "") as ftp_addrs_raw, IFNULL(u.ftp_user_raw, "") as ftp_user_raw, IFNULL(u.ftp_passwd_raw, "") as ftp_passwd_raw, IFNULL(u.ftp_filename_raw, "") as ftp_filename_raw, IFNULL(u.ftp_parm_raw, "") as ftp_parm_raw, IFNULL(u.ftp_target_raw, "") as ftp_target_raw, t.unit_id, s.`desc` as statustools, u.inoltro_ftp_raw, u.inoltro_api_raw, IFNULL(u.inoltro_api_url_raw, "") as inoltro_api_url_raw, IFNULL(u.inoltro_api_bearer_token_raw, "") as inoltro_api_bearer_token_raw, t.api_send_raw, IFNULL(u.duedate, "") as duedate from matfuncs as m inner join tools as t on t.matfunc = m.id inner join units as u on u.id = t.unit_id inner join statustools as s on t.statustool_id = s.id where t.name = "' . $tool . '" and u.name = "' . $unit . '";' ) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr"; $sth3->execute(); if ( $sth3->rows eq 0 ) { die getTimeStamp("log") . " - pid $$ >> Check tool status later - No tool's matlab function selected.\n"; } else { while ( my $results3 = $sth3->fetchrow_hashref ) { $tool_status3 = $results3->{'statustools'}; $ftp_send_raw = $results3->{'ftp_send_raw'}; $ftp_mode_raw = $results3->{'ftp_mode_raw'}; $ftp_addrs_raw = $results3->{'ftp_addrs_raw'}; $ftp_user_raw = $results3->{'ftp_user_raw'}; $ftp_passwd_raw = $results3->{'ftp_passwd_raw'}; $ftp_filename_raw = $results3->{'ftp_filename_raw'}; $ftp_target_raw = $results3->{'ftp_target_raw'}; $inoltro_ftp_raw = $results3->{'inoltro_ftp_raw'}; # $inoltro_api_raw = $results3->{'inoltro_api_raw'}; $inoltro_api_url_raw = $results3->{'inoltro_api_url_raw'}; $inoltro_api_bearer_token_raw = $results3->{'inoltro_api_bearer_token_raw'}; $api_send_raw = $results3->{'api_send_raw'}; # $unit_duedate = $results3->{'duedate'}; } } $sth3->finish; # Disconnect $dbh3->disconnect; #INOLTRO RAW CSV print getTimeStamp("log") . " - pid $$ >> DEBUG inoltro RAW filename: $filename\n"; #print getTimeStamp("log") . " - pid $$ >> $ftp_send_raw $ftp_addrs_raw $ftp_user_raw $ftp_passwd_raw\n"; if($inoltro_ftp_raw eq 1 && $ftp_send_raw eq 1 && $ftp_addrs_raw ne "" && $ftp_user_raw ne "" && $ftp_passwd_raw ne ""){ if($ftp_target_raw eq ""){ $ftp_target_raw = "/"; } print getTimeStamp("log") . " - pid $$ >> DEBUG inoltro RAW filenameraw: $ftp_filename_raw -- $tool\n"; if($ftp_filename_raw eq ""){ #print getTimeStamp("log") . " - pid $$ >> DEBUG inoltro RAW: 1\n"; $ftp_filename_raw = $filecsvname; }else{ #print getTimeStamp("log") . " - pid $$ >> DEBUG inoltro RAW: 2 $filecsvname\n"; $ftp_filename_raw =~ s/\$tool/$filecsvname/g; } #$ftp_filename_raw = "test"; if (!defined $unit_duedate || $unit_duedate eq '' || $unit_duedate eq '0000-00-00 00:00:00') { # duedate is empty or "0000-00-00 00:00:00", so proceed print getTimeStamp("log") . " - pid $$ >> DEBUG inoltro RAW: /home/battilo/scripts/FTPCSVRAW_v2.sh $ftp_addrs_raw $ftp_target_raw $filename $ftp_filename_raw$suffix $ftp_user_raw $ftp_passwd_raw\n"; system("sh /home/battilo/scripts/FTPCSVRAW_v2.sh $ftp_addrs_raw $ftp_target_raw $filename $ftp_filename_raw$suffix $ftp_user_raw $ftp_passwd_raw"); } else { my $duedateTmp1 = Time::Piece->strptime($unit_duedate, "%Y-%m-%d %H:%M:%S"); my $now1 = localtime; if ($duedateTmp1 >= $now1) { # duedate is valid and not expired, so proceed print getTimeStamp("log") . " - pid $$ >> DEBUG inoltro RAW: /home/battilo/scripts/FTPCSVRAW_v2.sh $ftp_addrs_raw $ftp_target_raw $filename $ftp_filename_raw$suffix $ftp_user_raw $ftp_passwd_raw\n"; system("sh /home/battilo/scripts/FTPCSVRAW_v2.sh $ftp_addrs_raw $ftp_target_raw $filename $ftp_filename_raw$suffix $ftp_user_raw $ftp_passwd_raw"); }else{ print getTimeStamp("log") . " - pid $$ >> centralina ($filename) scaduta! no ftp inoltro raw.\n"; } } } #INOLTRO RAW API if($inoltro_api_raw eq 1 && $api_send_raw eq 1 && $inoltro_api_url_raw ne ""){ if (!defined $unit_duedate || $unit_duedate eq '' || $unit_duedate eq '0000-00-00 00:00:00') { # duedate is empty or "0000-00-00 00:00:00", so proceed print getTimeStamp("log") . " - pid $$ >> DEBUG inoltro RAW API: /home/battilo/scripts/inoltroViaApiRaw.py $filename $inoltro_api_url_raw $inoltro_api_bearer_token_raw\n"; exec("/home/battilo/scripts/inoltroViaApiRaw.py \"$filename\" \"$inoltro_api_url_raw\" \"$inoltro_api_bearer_token_raw\" >> /home/asega/log/logInoltroViaApiRaw.log 2>&1"); } else { my $duedateTmp2 = Time::Piece->strptime($unit_duedate, "%Y-%m-%d %H:%M:%S"); my $now2 = localtime; if ($duedateTmp2 >= $now2) { # duedate is valid and not expired, so proceed print getTimeStamp("log") . " - pid $$ >> DEBUG inoltro RAW API: /home/battilo/scripts/inoltroViaApiRaw.py $filename $inoltro_api_url_raw $inoltro_api_bearer_token_raw\n"; exec("/home/battilo/scripts/inoltroViaApiRaw.py \"$filename\" \"$inoltro_api_url_raw\" \"$inoltro_api_bearer_token_raw\" >> /home/asega/log/logInoltroViaApiRaw.log 2>&1"); }else{ print getTimeStamp("log") . " - pid $$ >> centralina ($filename) scaduta! no api inoltro raw.\n"; } } } # if($tool_status3 eq "Test"){ print getTimeStamp("log") . " - pid $$ >> tool status: $tool_status3 nothing to do.\n"; }else{#insert in RAW table if(($unit eq "ID0070" && $tool eq "DT0111") || ($unit eq "ID0071" && $tool eq "DT0112") || ($unit eq "ID0072" && $tool eq "DT0113") || ($unit eq "ID0073" && $tool eq "DT0114") || ($unit eq "ID0273" && $tool eq "DT0001") || ($unit eq "ID0279" && $tool eq "DT0008")){ modifyAndWriteOutSql($tool); } writeOutSql($tool); } if ( $tooltype eq "GD" ) { print getTimeStamp("log") . " - pid $$ >> tool GD: nothing to do.\n"; } else { getMatlabCmd(); print getTimeStamp("log") . " - pid $$ >> $unit - $tool - Status $tool_status.\n"; if ( $tool_status eq 'Active' || $tool_status eq 'Manual Upload' ) { matlabCalc(); if ($ftp_send) { if ( $tool eq 'DT0076' ) { sleep(600); } trxelab(); } if($inoltro_api eq 1 && $api_send eq 1){ if (!defined $unit_duedate || $unit_duedate eq '' || $unit_duedate eq '0000-00-00 00:00:00') { # duedate is empty or "0000-00-00 00:00:00", so proceed trxelabApi(); } else { my $duedateTmp = Time::Piece->strptime($unit_duedate, "%Y-%m-%d %H:%M:%S"); my $now = localtime; if ($duedateTmp >= $now) { # duedate is valid and not expired, so proceed trxelabApi(); }else{ print getTimeStamp("log") . " - pid $$ >> $unit: scaduta! no api inoltro elab.\n"; } } } } else { print getTimeStamp("log") . " - pid $$ >> $unit - $tool - $tool_status: MatLab calc by-passed.\n"; } } print getTimeStamp("log") . " - pid $$ >> Execution ended.\n"; exit;