user e pwd x db company

This commit is contained in:
2017-09-17 23:23:58 +02:00
parent 980477fdfd
commit 151149c155

View File

@@ -9,22 +9,26 @@ use Data::Dumper qw(Dumper);
$|++; # Autoflush $|++; # Autoflush
my ($filename, $sqlout); my ( $filename, $sqlout );
my $username = 'ase_lar'; my $username = 'ase_lar';
my $password = 'laravel'; my $password = 'laravel';
my $db_lar = 'ase_lar'; my $db_lar = 'ase_lar';
my $server = 'localhost'; my $db_sp = 'ase_lar';
my $db_name = "ase_mums"; my $server = 'localhost';
my $table = "RAWDATA"; my $db_name = "ase_mums";
my (@CSVData, @sql); my $table = "RAWDATA";
my $outcount = 0; my ( @CSVData, @sql );
my $outfilenum = 0; my $outcount = 0;
my $outfilenum = 0;
my $maxsqllines = 10000; my $maxsqllines = 10000;
my ($tool, $toolbatt, $tooltemp, $tooltype, @channels, @NewData, @din, @nodetype); my (
my $matlab_ip = "160.78.21.71"; $tool, $toolbatt, $tooltemp, $tooltype,
my $matlab_cmd = "matlab.cmd"; @channels, @NewData, @din, @nodetype
);
my $matlab_ip = "160.78.21.71";
my $matlab_cmd = "matlab.cmd";
my $matlab_timestamp = ""; my $matlab_timestamp = "";
my $ftp_send = 1; my $ftp_send = 1;
my $ftp_addrs; my $ftp_addrs;
my $ftp_user; my $ftp_user;
my $ftp_passwd; my $ftp_passwd;
@@ -33,87 +37,126 @@ my $ftp_filename;
my $ftp_target; my $ftp_target;
my $unit_id; my $unit_id;
sub getTimeStamp { # parm [ts] => timestamp for filename; log => timestamp for log sub getTimeStamp
my $format = "%04d%02d%02d%02d%02d%02d"; { # parm [ts] => timestamp for filename; log => timestamp for log
my ($p1) = @_; my $format = "%04d%02d%02d%02d%02d%02d";
if (defined $p1 and $p1 eq "log") { my ($p1) = @_;
$format = "%04d%02d%02d %02d:%02d:%02d"; 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"; 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); my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =
return $timestamp; localtime(time);
my $timestamp =
sprintf( $format, $year + 1900, $mon + 1, $mday, $hour, $min, $sec );
return $timestamp;
} }
sub writeOutSql { sub writeOutSql {
my ($tn) = @_; my ($tn) = @_;
my $outfile = $sqlout . "_" . $outfilenum++; my $outfile = $sqlout . "_" . $outfilenum++;
open SQLOUT, ">", $outfile or die(getTimeStamp("log") . " - pid $$ >> Error: opening output file " . $outfile . ":$!\n"); open SQLOUT, ">", $outfile
print getTimeStamp("log") . " - pid $$ >> file $outfile created\n"; or die( getTimeStamp("log")
print SQLOUT "/* lock " . $db_name . ".$table table */\nLOCK TABLES " . $db_name . ".$table WRITE;\n"; . " - pid $$ >> Error: opening output file "
print SQLOUT "INSERT IGNORE INTO " . $db_name . ".$table\n"; . $outfile
print SQLOUT "(`UnitName`,`ToolNameID`,`NodeNum`,`EventDate`,`EventTime`,`BatLevel`,`Temperature`,\n"; . ":$!\n" );
print SQLOUT "`Val0`,`Val1`,`Val2`,`Val3`,`Val4`,`Val5`,`Val6`,`Val7`,`Val8`,`Val9`,`ValA`,`ValB`,`ValC`,`ValD`,`ValE`,`ValF`)\n"; print getTimeStamp("log") . " - pid $$ >> file $outfile created\n";
print SQLOUT "VALUES\n"; print SQLOUT "/* lock "
print SQLOUT @sql; . $db_name
@sql = (); . ".$table table */\nLOCK TABLES "
print SQLOUT "/* unlock table */\nUNLOCK TABLES;\n"; . $db_name
print SQLOUT "/* call stored procedure to copy in ase_lar */\ncall ase_lar.CopyAndFill('$tn');\n"; . ".$table WRITE;\n";
close SQLOUT or die(getTimeStamp("log") . " - pid $$ >> Error in closing file " . $outfile . "\n"); print SQLOUT "INSERT IGNORE INTO " . $db_name . ".$table\n";
my @args = ("mysql", "--login-path=asepath", "-e source " . $outfile); print SQLOUT
system(@args) == 0 or die (getTimeStamp("log") . " - pid $$ >> system @args failed: $?\n"); "(`UnitName`,`ToolNameID`,`NodeNum`,`EventDate`,`EventTime`,`BatLevel`,`Temperature`,\n";
print getTimeStamp("log") . " - pid $$ >> file $outfile loaded into DB\n"; print SQLOUT
unlink $outfile; "`Val0`,`Val1`,`Val2`,`Val3`,`Val4`,`Val5`,`Val6`,`Val7`,`Val8`,`Val9`,`ValA`,`ValB`,`ValC`,`ValD`,`ValE`,`ValF`)\n";
return; print SQLOUT "VALUES\n";
print SQLOUT @sql;
@sql = ();
print SQLOUT "/* unlock table */\nUNLOCK TABLES;\n";
print SQLOUT "/* call stored procedure to copy in "
. $db_sp
. "*/\ncall "
. $db_sp
. ".CopyAndFill('$tn');\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 matlabCalc { sub matlabCalc {
getMatlabCmd(); getMatlabCmd();
$matlab_timestamp = getTimeStamp("db_ts"); $matlab_timestamp = getTimeStamp("db_ts");
print getTimeStamp("log") . " - pid $$ >> $tool MatLab calc started...\n"; print getTimeStamp("log") . " - pid $$ >> $tool MatLab calc started...\n";
my @out_matlab = `ssh1 $matlab_ip 'cmd /c $matlab_cmd ' $tool`; my @out_matlab = `ssh1 $matlab_ip 'cmd /c $matlab_cmd ' $tool`;
print getTimeStamp("log") . " - pid $$ >> $tool MatLab calc executed: $out_matlab[-1]"; print getTimeStamp("log")
#print getTimeStamp("log") . " - @out_matlab"; . " - pid $$ >> $tool MatLab calc executed: $out_matlab[-1]";
#print getTimeStamp("log") . " - pid $$ >> $out_matlab[-1]";
return; #print getTimeStamp("log") . " - @out_matlab";
#print getTimeStamp("log") . " - pid $$ >> $out_matlab[-1]";
return;
} }
sub trxelab { sub trxelab {
my $dbh = DBI->connect("DBI:mysql:$db_lar;host=$server", $username, $password) my $dbh =
or die getTimeStamp("log") . " - Could not connect to database: $DBI::errstr"; 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 ftp_addrs, ftp_user, ftp_passwd, ftp_parm, ftp_filename, ftp_target from units my $sth = $dbh->prepare(
where id = ' . $unit_id . ';') or die getTimeStamp("log") . " - $DBI::errstr"; 'select ftp_addrs, ftp_user, ftp_passwd, ftp_parm, ftp_filename, ftp_target from units
where id = ' . $unit_id . ';'
) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
$sth->execute(); $sth->execute();
if ($sth->rows < 0) { if ( $sth->rows < 0 ) {
die getTimeStamp("log") . " - No unit ftp params selected.\n"; die getTimeStamp("log") . " - pid $$ >> No unit ftp params selected.\n";
} else { }
while (my $results = $sth->fetchrow_hashref) { else {
$ftp_addrs = $results->{'ftp_addrs'}; while ( my $results = $sth->fetchrow_hashref ) {
$ftp_user = $results->{'ftp_user'}; $ftp_addrs = $results->{'ftp_addrs'};
$ftp_passwd = $results->{'ftp_passwd'}; $ftp_user = $results->{'ftp_user'};
$ftp_parm = $results->{'ftp_parm'}; $ftp_passwd = $results->{'ftp_passwd'};
$ftp_filename = $results->{'ftp_filename'}; $ftp_parm = $results->{'ftp_parm'};
$ftp_target = $results->{'ftp_target'}; $ftp_filename = $results->{'ftp_filename'};
$ftp_target = $results->{'ftp_target'};
}
} }
}
$sth->finish; $sth->finish;
# Disconnect
my $fileelab; # Disconnect
if ($ftp_filename eq "") {
$fileelab = '/var/lib/mysql-files/' . $tool . '_' . getTimeStamp() . '.csv'; #mettere quello che si prende da query
} else {
$ftp_filename =~ s/(\$\w+)/$1/eeg;
$ftp_filename =~ s/\s/_/g;
$fileelab = '/var/lib/mysql-files/' . $ftp_filename . '_' . getTimeStamp() . '.csv';
}
my $sthdo = $dbh->do( qq{ my $fileelab;
if ( $ftp_filename eq "" ) {
$fileelab =
'/var/lib/mysql-files/'
. $tool . '_'
. getTimeStamp()
. '.csv'; #mettere quello che si prende da query
}
else {
$ftp_filename =~ s/(\$\w+)/$1/eeg;
$ftp_filename =~ s/\s/_/g;
$fileelab =
'/var/lib/mysql-files/'
. $ftp_filename . '_'
. getTimeStamp() . '.csv';
}
my $sthdo = $dbh->do(
qq{
select * from ( select * from (
( (
select 'ToolNameID', 'EventDate', 'EventTime', 'NodeNum', 'NodeType', 'NodeDepth', select 'ToolNameID', 'EventDate', 'EventTime', 'NodeNum', 'NodeType', 'NodeDepth',
@@ -132,182 +175,264 @@ sub trxelab {
) resulting_set ) resulting_set
into outfile '$fileelab' into outfile '$fileelab'
fields terminated by ',' optionally enclosed by '"' lines terminated by '\n'}) or die getTimeStamp("log") . " - $DBI::errstr"; fields terminated by ',' optionally enclosed by '"' lines terminated by '\n'}
) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
$dbh->disconnect; $dbh->disconnect;
$ftp_parm //= ""; $ftp_parm //= "";
if ($ftp_parm ne "") { if ( $ftp_parm ne "" ) {
$ftp_parm = "debug => 0, " . $ftp_parm; $ftp_parm = "debug => 0, " . $ftp_parm;
} else { }
$ftp_parm = "debug => 0"; else {
} $ftp_parm = "debug => 0";
}
print getTimeStamp("log") . " - pid $$ >> $tool: ftp parm = $ftp_parm.\n"; print getTimeStamp("log") . " - pid $$ >> $tool: ftp parm = $ftp_parm.\n";
my $ftp = Net::FTP->new($ftp_addrs, debug => 0) my $ftp = Net::FTP->new( $ftp_addrs, debug => 0 )
or die getTimeStamp("log") . " - pid $$ >> Cannot connect to $ftp_addrs: $@ \n"; or die getTimeStamp("log")
$ftp->login($ftp_user,$ftp_passwd) . " - pid $$ >> Cannot connect to $ftp_addrs: $@ \n";
or die getTimeStamp("log") . " - pid $$ >> Cannot login " . $ftp->message . "\n"; $ftp->login( $ftp_user, $ftp_passwd )
$ftp_target //= ""; or die getTimeStamp("log")
if ($ftp_target ne "") { . " - pid $$ >> Cannot login "
$ftp->cwd($ftp_target) . $ftp->message . "\n";
or die getTimeStamp("log") . " - pid $$ >> Change remote dir failed " . $ftp->message . "\n"; $ftp_target //= "";
} if ( $ftp_target ne "" ) {
$ftp->cwd($ftp_target)
or die getTimeStamp("log")
. " - pid $$ >> Change remote dir failed "
. $ftp->message . "\n";
}
print getTimeStamp("log") . " - pid $$ >> ftp target: " . $ftp->pwd() . ".\n"; print getTimeStamp("log")
. " - pid $$ >> ftp target: "
. $ftp->pwd() . ".\n";
$ftp->put($fileelab) $ftp->put($fileelab)
or die getTimeStamp("log") . " - pid $$ >> Put failed " . $ftp->message . "\n"; or die getTimeStamp("log")
$ftp->quit; . " - pid $$ >> Put failed "
print getTimeStamp("log") . " - pid $$ >> $tool: $fileelab ftp put executed.\n"; . $ftp->message . "\n";
return; $ftp->quit;
print getTimeStamp("log")
. " - pid $$ >> $tool: $fileelab ftp put executed.\n";
return;
} }
sub getNodesType { sub getNodesType {
my $dbh = DBI->connect("DBI:mysql:$db_lar;host=$server", $username, $password) my $dbh =
or die getTimeStamp("log") . " - Could not connect to database: $DBI::errstr"; 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.din as din 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.din as din
from nodes as n from nodes as n
inner join tools as t on t.id = n.tool_id inner join tools as t on t.id = n.tool_id
inner join nodetypes as y on n.nodetype_id = y.id inner join nodetypes as y on n.nodetype_id = y.id
where t.name = "' . $tool . '" order by 3;') or die getTimeStamp("log") . " - $DBI::errstr"; where t.name = "' . $tool . '" order by 3;'
) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
$sth->execute(); $sth->execute();
if ($sth->rows < 0) { if ( $sth->rows < 0 ) {
die getTimeStamp("log") . " - No node channels selected.\n"; die getTimeStamp("log") . " - pid $$ >> No node channels selected.\n";
} else { }
my $row = 0; else {
while (my $results = $sth->fetchrow_hashref) { my $row = 0;
$channels[$row] = $results->{'channels'}; while ( my $results = $sth->fetchrow_hashref ) {
$nodetype[$row] = $results->{'type'}; $channels[$row] = $results->{'channels'};
$din[$row++] = $results->{'din'}; $nodetype[$row] = $results->{'type'};
$din[ $row++ ] = $results->{'din'};
}
} }
}
$sth->finish; $sth->finish;
# Disconnect
$dbh->disconnect; # Disconnect
return; $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_pwd FROM ase_lar.companies where db_name = '"
. $db_name
. "';" )
or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
$sth->execute();
if ( $sth->rows < 0 ) {
die getTimeStamp("log") . " - pid $$ >> No password selected.\n";
}
else {
my $mfunc;
while ( my $results = $sth->fetchrow_hashref ) {
$password = $results->{'db_pwd'};
$username = $results->{'db_user'};
}
}
$sth->finish;
# Disconnect
$dbh->disconnect;
return;
} }
sub getMatlabCmd { sub getMatlabCmd {
my $dbh = DBI->connect("DBI:mysql:$db_lar;host=$server", $username, $password) my $dbh =
or die getTimeStamp("log") . " - Could not connect to database: $DBI::errstr"; 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 from matfuncs as m my $sth = $dbh->prepare(
'select m.matcall, t.ftp_send , t.unit_id from matfuncs as m
inner join tools as t on t.matfunc = m.id inner join tools as t on t.matfunc = m.id
where t.name = "' . $tool . '" ;') or die getTimeStamp("log") . " - $DBI::errstr"; where t.name = "' . $tool . '" ;'
) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
$sth->execute(); $sth->execute();
if ($sth->rows < 0) { if ( $sth->rows < 0 ) {
die getTimeStamp("log") . " - No tool's matlab function selected.\n"; die getTimeStamp("log")
} else { . " - pid $$ >> No tool's matlab function selected.\n";
my $mfunc; }
while (my $results = $sth->fetchrow_hashref) { else {
$mfunc = uc $results->{'matcall'}; my $mfunc;
$ftp_send = $results->{'ftp_send'}; while ( my $results = $sth->fetchrow_hashref ) {
$unit_id = $results->{'unit_id'}; $mfunc = uc $results->{'matcall'};
$ftp_send = $results->{'ftp_send'};
$unit_id = $results->{'unit_id'};
}
$matlab_cmd = 'matlab_' . $mfunc . '.cmd';
} }
$matlab_cmd = 'matlab_' . $mfunc . '.cmd';
}
$sth->finish; $sth->finish;
# Disconnect
$dbh->disconnect; # Disconnect
return; $dbh->disconnect;
return;
} }
my $starttime = getTimeStamp("log"); my $starttime = getTimeStamp("log");
print "$starttime - pid $$ >> Start execution.\n"; print "$starttime - pid $$ >> Start execution.\n";
GetOptions ("filename=s" => \$filename, GetOptions(
"sqlout=s" => \$sqlout, "filename=s" => \$filename,
"dbname=s" => \$db_name) "sqlout=s" => \$sqlout,
or die("Error in command line arguments\n"); "dbname=s" => \$db_name
open FILE, $filename or die("Error: opening input file " . $filename . "\n"); ) or die("Error in command line arguments\n");
open FILE, $filename
or die( "Error: opening input file " . $filename . "\n" );
my ($fileDate, $fileTime) = split(/\s/, <FILE>); if ( $db_name ne 'asega' ) {
my ($unittype, $unit) = split(/\s/, uc <FILE>); $db_name =~ s/dbn/dbu/;
$db_sp = $db_name;
getUdbPwd();
}
else {
$db_name = 'ase_mums';
}
while (my $line = <FILE>) { my ( $fileDate, $fileTime ) = split( /\s/, <FILE> );
my($first, $NodeData) = split(/;/, $line, 2); my ( $unittype, $unit ) = split( /\s/, uc <FILE> );
if ( defined $first and ($first ne '')) {
if ( ! defined $NodeData or ($NodeData =~ m/^;+/) ) {
my @info = (split(/[\/,\.]/, $first));
if (defined $info[3] && $info[3] =~ m/^DT\d\d\d\d$/i ) {
$tool= uc $info[3];
$tooltype = uc $info[2];
print getTimeStamp("log") . " - pid $$ >> Found $tooltype tool name: $tool\n";
getNodesType();
} elsif (defined $info[2] && $info[2] =~ m/^LOC\d*$/i ) {
$tool= uc $info[2];
$tooltype = 'LOC';
print getTimeStamp("log") . " - pid $$ >> Found $tooltype tool name: $tool\n";
getNodesType();
}
} else {
$NodeData =~ s/\x0d{0,1}\x0a\Z//s;
#$NodeData =~ s/\r\n\z//;
if ($tooltype eq "MUX" ) { while ( my $line = <FILE> ) {
#$NodeData =~ s/Dis\./N\/A/g; my ( $first, $NodeData ) = split( /;/, $line, 2 );
@NewData = grep /\S/, split(/\||;/,$NodeData); if ( defined $first and ( $first ne '' ) ) {
my $idx = 0; if ( !defined $NodeData or ( $NodeData =~ m/^;+/ ) ) {
$CSVData[$idx++] = join( ';', splice(@NewData, 0, 2)); my @info = ( split( /[\/,\.]/, $first ) );
foreach my $ch (@channels) { if ( defined $info[3] && $info[3] =~ m/^DT\d\d\d\d$/i ) {
$CSVData[$idx++] = join( ';', splice(@NewData, 0, $ch)); $tool = uc $info[3];
} $tooltype = uc $info[2];
#print Dumper \@NewData; print getTimeStamp("log")
#print Dumper \@din; . " - pid $$ >> Found $tooltype tool name: $tool\n";
} elsif ($tooltype eq "LOC") { getNodesType();
if (!defined $din[0]) { }
print getTimeStamp("log") . " - pid $$ >> Din not defined.\n"; elsif ( defined $info[2] && $info[2] =~ m/^LOC\d*$/i ) {
print getTimeStamp("log") . " - pid $$ >> Execution ended.\n"; $tool = uc $info[2];
exit; $tooltype = 'LOC';
}; print getTimeStamp("log")
my ($Vbat, $Tmod, $Ain1, $Ain2, $Din1, $Din2) = split(/;/,$NodeData); . " - pid $$ >> Found $tooltype tool name: $tool\n";
$CSVData[0] = $Vbat . ";" . $Tmod; getNodesType();
$CSVData[1] = $Din1; }
} else { }
@CSVData = split(/\|/,$NodeData); else {
} $NodeData =~ s/\x0d{0,1}\x0a\Z//s;
my $nodenum = 0; #$NodeData =~ s/\r\n\z//;
foreach (@CSVData) {
$sql[($outcount%$maxsqllines)] = ""; if ( $tooltype eq "MUX" ) {
my(@data) = grep {/\S/} split(/\;/,$_);
if ($nodenum eq 0) { #$NodeData =~ s/Dis\./N\/A/g;
$toolbatt = $data[0]; @NewData = grep /\S/, split( /\||;/, $NodeData );
$tooltemp = $data[1]; my $idx = 0;
} else { $CSVData[ $idx++ ] = join( ';', splice( @NewData, 0, 2 ) );
my($y, $m, $d, $t) = split(/[\s\/]/,$first); foreach my $ch (@channels) {
foreach (@data) { $CSVData[ $idx++ ] =
if ($sql[($outcount%$maxsqllines)] eq "") { join( ';', splice( @NewData, 0, $ch ) );
$sql[($outcount%$maxsqllines)] = "('$unit','$tool','$nodenum','$y-$m-$d','$t','$toolbatt','$tooltemp'"; }
}
$sql[($outcount%$maxsqllines)] .= ",'" . $_ . "'"; #print Dumper \@NewData;
} #print Dumper \@din;
my $InsCompl = ",NULL" x (15 - $#data); }
$sql[($outcount%$maxsqllines)] .= $InsCompl . ")"; elsif ( $tooltype eq "LOC" ) {
if (++$outcount%$maxsqllines eq 0) { if ( !defined $din[0] ) {
$sql[($outcount%$maxsqllines)-1] .= ";\n"; print getTimeStamp("log")
writeOutSql($tool); . " - pid $$ >> Din not defined.\n";
} else { print getTimeStamp("log")
$sql[($outcount%$maxsqllines)-1] .= ",\n"; . " - pid $$ >> Execution ended.\n";
} exit;
} }
$nodenum++; my ( $Vbat, $Tmod, $Ain1, $Ain2, $Din1, $Din2 ) =
} split( /;/, $NodeData );
} $CSVData[0] = $Vbat . ";" . $Tmod;
} $CSVData[1] = $Din1;
}
else {
@CSVData = split( /\|/, $NodeData );
}
my $nodenum = 0;
foreach (@CSVData) {
$sql[ ( $outcount % $maxsqllines ) ] = "";
my (@data) = grep { /\S/ } split( /\;/, $_ );
if ( $nodenum eq 0 ) {
$toolbatt = $data[0];
$tooltemp = $data[1];
}
else {
my ( $y, $m, $d, $t ) = split( /[\s\/]/, $first );
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";
writeOutSql($tool);
}
else {
$sql[ ( $outcount % $maxsqllines ) - 1 ] .= ",\n";
}
}
$nodenum++;
}
}
}
} }
close FILE; close FILE;
$sql[($outcount%$maxsqllines)-1] =~ s/,$/;/g; $sql[ ( $outcount % $maxsqllines ) - 1 ] =~ s/,$/;/g;
writeOutSql($tool); writeOutSql($tool);
matlabCalc(); matlabCalc();
if ($ftp_send) { if ($ftp_send) {
trxelab(); trxelab();
} }
print getTimeStamp("log") . " - pid $$ >> Execution ended.\n"; print getTimeStamp("log") . " - pid $$ >> Execution ended.\n";