#!/usr/bin/perl use warnings; use strict; use Getopt::Long; use File::SmartTail; use File::Basename qw( fileparse ); use File::Path qw( make_path ); use File::Copy qw( move ); use POSIX; use DBI; $SIG{CHLD} = 'IGNORE'; $|++; # Autoflush my $username = 'aselar'; my $password = 'laravel'; my $db_lar = 'ase_lar'; my $server = '85.235.153.201'; 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"; } 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 getUnitName { # parm => file received ($trfile) my ($filename) = @_; my ( $fileDate, $fileTime ); my ( $unittype, $unit ); my ( $ipdescgd, $ipgd ); #per gd modb my ( $subnetdescgd, $subnetgd ); #per gd modb my ( $gatewaydescgd, $gatewaygd ); #per gd modb my ( $sdpathdescgd, $dfpathdescpathgd, $sdpathgd ); #per gd modb my ( $filenamecsv, $path, $suffix ) = fileparse( $filename, qr/\.[^.]*/ ); #print getTimeStamp("log") . " >> DEBUG -> $filenamecsv\n"; if ( $path =~ m/ID\d\d\d\d\/*$/i ) { my @strings = $path =~ /.*\/(ID.{1,4})\/*$/; $unit = $strings[0]; } elsif( $path =~ m/TS[^\/]*\/*$/i ){#cartelle stazioni totale, per le stazioni totali la cartella deve iniziare con TS seguito da qualsiasi carattere non / #print getTimeStamp("log") . " >> DEBUG DENTRO!\n"; my @strings = $path =~ /.*\/(TS[^\/]*)\/*$/; $unit = $strings[0]; } if ( $filenamecsv =~ m/^G201_ID\d\d\d\d_DT\d\d\d\d_\d*$/i ) { 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/^G201_ID\d\d\d\d_DT\d\d\d\d\d*$/i ) {#se manca _ prima della data 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/^TLP_ID\d\d\d\d_DT\d\d\d\d_\d*$/i ) { 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/^TLP_ID\d\d\d\d_DT\d\d\d\d\d*$/i ) {#se manca _ prima della data 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/^GS1_ID\d\d\d\d_DT\d\d\d\d_\d*$/i ) { 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/^GS1_ID\d\d\d\d_DT\d\d\d\d\d*$/i ) {#se manca _ prima della data 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/^GS1_ID\d\d\d\d\d_DT\d\d\d\d_\d*$/i ) { my @strings = $filenamecsv =~ /(.{1,4})_(.{1,7})_(.{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/^GS1_ID\d\d\d\d\d_DT\d\d\d\d\d*$/i ) {#se manca _ prima della data my @strings = $filenamecsv =~ /(.{1,4})_(.{1,7})_(.{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/^GFLOW_ID\d\d\d\d_DT\d\d\d\d_\d*$/i ) { my @strings = $filenamecsv =~ /(.{1,5})_(.{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/^measurements_\d\d_\d\d_\d\d\d\d__\d\d_\d\d$/i ) { $unittype = "NESA"; } elsif ( $filenamecsv =~ m/^\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d$/i ) { # nesa file con serial number centralina $unittype = "NESA"; } 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]; } elsif ( $filenamecsv =~ m/^CR1000X_ID\d\d\d\d_DT\d\d\d\d$/i ) { my @strings = $filenamecsv =~ /(.{1,7})_(.{1,6})_(.{1,6}).*/; $unittype = $strings[0]; $unit = $strings[1]; } elsif ( $filenamecsv =~ m/^(\d*_|)G301_ID\d\d\d\d_DT\d\d\d\d$/i ) { my $filecsvname_clean = substr( $filenamecsv, index( $filenamecsv, "G301" ) ); my @strings = $filecsvname_clean =~ /(.{1,4})_(.{1,6})_(.{1,6}).*/; $unittype = $strings[0]; $unit = $strings[1]; } elsif( $filenamecsv =~ m/^(\d*-|)health-\d\d\d\d_\d\d_\d\d_\d\d_\d\d_\d\d$/i ){ # sisgeo unit #56371-health-2022_12_01_05_31_05.csv #56371-readings-2022_12_01_06_00_00.csv $unittype = "SISGEO"; } elsif( $filenamecsv =~ m/^(\d*-|)readings-\d\d\d\d_\d\d_\d\d_\d\d_\d\d_\d\d$/i ){ # sisgeo unit #56371-health-2022_12_01_05_31_05.csv #56371-readings-2022_12_01_06_00_00.csv $unittype = "SISGEO"; } elsif($filenamecsv =~ m/^MesspunktePini_/ or $filenamecsv =~ m/^Integrity Monitor /){ #stazione totale mire $unittype = "STAZIONETOTALE"; } elsif($filenamecsv =~ m/^CO_\d\d\d\d_\d_\d\d\d\d\d\d\d\d_\d\d\d\d\d\d$/i ){#sorotec pini $unittype = "SOROTECPINI"; } elsif($filenamecsv =~ m/^CO_\d\d\d\d_\d_\d\d\d\d\d\d\d\d_\d\d\d\d\d\d_\d\d\d\d\d\d\d\d\d\d\d\d\d\d$/i ){#sorotec pini $unittype = "SOROTECPINI"; } elsif($filenamecsv =~ m/^HIRPINIA/){#hirpinia $unittype = "HIRPINIA"; } elsif ( $filenamecsv =~ m/^\d\d\d\d\d\d\d_\d\d\d\d-\d\d-\d\d_\d\d-\d\d-\d\d_\d.log$/i ) {#vulink pini $unittype = "VULINK"; } else { open FILE, $filename or warn getTimeStamp("log") . " >> Error: opening input file $filename\n"; ( $fileDate, $fileTime ) = split( /\s/, ); ( $unittype, $unit ) = split( /\s/, uc ); if($filenamecsv =~ m/^GD\d\d\d\d$/i){ #per gd modb ( $ipdescgd, $ipgd ) = split( /\s/, ); ( $subnetdescgd, $subnetgd ) = split( /\s/, ); ( $gatewaydescgd, $gatewaygd ) = split( /\s/, ); ( $sdpathdescgd, $dfpathdescpathgd, $sdpathgd ) = split( /\s/, ); #print getTimeStamp("log"). " >> DEBUG unittype: $unittype unit: $unit SD path: $sdpathgd\n"; } $unit =~ s/;+$//; close FILE; } return ( $unit, $unittype, $sdpathgd ); } my $readingFile; my $recvOKstr = "OK UPLOAD"; my @ext = ( ".csv", ".txt", ".ods" ); GetOptions( "file=s" => \$readingFile ) or die("Error in command line arguments\n"); my ( $scriptname, $scriptpath ) = fileparse($0); my $tail = new File::SmartTail; $tail->WatchFile( -file => $readingFile, -type => "UNIX", -timeout => '10' ); while ( my $line = $tail->GetLine() ) { if ( index( $line, $recvOKstr ) != -1 ) { my ( undef, undef, undef, $truser, undef, $trip, undef, $trfile, $trstat ) = split( /[\"\[\]]/, $line ); if(index($line, "Integrity Monitor [") != -1){#se รจ stazione di pini #print getTimeStamp("log") . " >> DEBUG line $line\n"; #my @sssa = split( /[\"\[\]]/, $line); #foreach my $value (@sssa) { # print "$value\n"; #} my ( undef, undef, undef, $trusertmp, undef, undef, $triptmp, $trfileuno, $trfiledue, $trfiletre, $trstattmp ) = split( /[\"\[\]]/, $line ); $trfile = $trfileuno."[".$trfiledue."]".$trfiletre;#per pini ts $truser = $trusertmp; $trip = $triptmp; $trstat = $trstattmp; #print("######\n"); #print($trfile."\n"); #print("---\n"); #print($truser."\n"); #print("---\n"); #print($trip."\n"); #print("---\n"); #print($trstat."\n"); #print("---\n"); } #print getTimeStamp("log") . " >> DEBUG line $line\n"; my ( $login, $pass, $uid, $gid ) = getpwnam($truser) or warn getTimeStamp("log") . " >> $truser not in passwd file.\n"; 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 stop_elab FROM admin_panel LIMIT 1"); $sth->execute(); my $stop_elab; if (my $row = $sth->fetchrow_hashref) { $stop_elab = $row->{'stop_elab'}; } else { $stop_elab = 0; } print getTimeStamp("log") . " >> stop_elab value -> $stop_elab.\n"; $sth->finish; if ($stop_elab == 0) { my $sth2 = $dbh->prepare("SELECT id, command, truser FROM elaborazioni_stoppate WHERE eseguito = 0"); $sth2->execute(); my $sth3 = $dbh->prepare("UPDATE elaborazioni_stoppate SET eseguito = 1 WHERE eseguito = 0"); $sth3->execute(); $sth3->finish; while (my $row2 = $sth2->fetchrow_hashref) { my $id = $row2->{'id'}; my $command = $row2->{'command'}; my $truser2 = $row2->{'truser'}; my ( $login2, $pass2, $uid2, $gid2 ) = getpwnam($truser2) or warn getTimeStamp("log") . " >> $truser2 not in passwd file.\n"; print getTimeStamp("log") . " >> DEBUG exec command -> $command.\n"; my $pid = fork(); unless ($pid) { setgid($gid2); setuid($uid2); $ENV{"HOME"} = 'home/' . $truser2; exec($command) or die "Failed to exec command for id $id: $!"; exit(0); } waitpid($pid, 0); } $sth2->finish; } $dbh->disconnect; #print getTimeStamp("log") . " >> DEBUG $trfile \n"; my ( $filename, $path, $suffix ) = fileparse( $trfile, qr/\.[^.]*/ ); #print getTimeStamp("log") . " >> DEBUG $filename --- $path --- $suffix \n"; $path = "/home/" . $truser . "/"; $trfile = "/home/" . $truser . $trfile; if ( ( grep( /^$suffix$/i, @ext ) ) and ( $filename =~ m/^(\d\d_\d\d\d\d_|)(DT\d\d\d\d|LOC\d\d\d\d|GD\d\d\d\d)$/i or $filename =~ m/^G201_ID\d\d\d\d_DT\d\d\d\d_\d*$/i or $filename =~ m/^G201_ID\d\d\d\d_DT\d\d\d\d\d*$/i or $filename =~ m/^TLP_ID\d\d\d\d_DT\d\d\d\d_\d*$/i or $filename =~ m/^TLP_ID\d\d\d\d_DT\d\d\d\d\d*$/i or $filename =~ m/^GS1_ID\d\d\d\d_DT\d\d\d\d_\d*$/i or $filename =~ m/^GS1_ID\d\d\d\d_DT\d\d\d\d\d*$/i or $filename =~ m/^GS1_ID\d\d\d\d\d_DT\d\d\d\d_\d*$/i or $filename =~ m/^GS1_ID\d\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 or $filename =~ m/^CR1000X_ID\d\d\d\d_DT\d\d\d\d$/i or $filename =~ m/^Hortus_ID\d\d\d\d_DT\d\d\d\d_\d\d\d\d\d\d\d\d\d\d\d\d\d\d$/i or $filename =~ m/^(\d*_|)G301_ID\d\d\d\d_DT\d\d\d\d$/i or $filename =~ m/^GFLOW_ID\d\d\d\d_DT\d\d\d\d_\d*$/i or $filename =~ m/^measurements_\d\d_\d\d_\d\d\d\d__\d\d_\d\d$/i or $filename =~ m/^\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d$/i or $filename =~ m/^(\d*-|)health-\d\d\d\d_\d\d_\d\d_\d\d_\d\d_\d\d$/i or $filename =~ m/^(\d*-|)readings-\d\d\d\d_\d\d_\d\d_\d\d_\d\d_\d\d$/i or $filename =~ m/^MesspunktePini_/ or $filename =~ m/^Integrity Monitor/ or $filename =~ m/^CO_\d\d\d\d_\d_\d\d\d\d\d\d\d\d_\d\d\d\d\d\d$/i or $filename =~ m/^CO_\d\d\d\d_\d_\d\d\d\d\d\d\d\d_\d\d\d\d\d\d_\d\d\d\d\d\d\d\d\d\d\d\d\d\d$/i or $filename =~ m/^HIRPINIA/ or $filename =~ m/^\d\d\d\d\d\d\d_\d\d\d\d-\d\d-\d\d_\d\d-\d\d-\d\d_\d.log$/i ) ) { if($filename =~ m/Hortus_ID\d\d\d\d_DT\d\d\d\d_\d\d\d\d\d\d\d\d\d\d\d\d\d\d/){#mancano i ; nelle prime 6 righe, aggiungo ; alla fine delle prime 6 righe dell'header open my $hortus_file, '+<', $trfile; my @hortus_file_lines = <$hortus_file>; $hortus_file_lines[0] =~ tr /\r/\n/; my @line_splitted = split(/\n/, $hortus_file_lines[0]); for(my $i_var_for=0; $i_var_for < 6; $i_var_for++){ unless($line_splitted[$i_var_for] =~ m';'){ $line_splitted[$i_var_for] = $line_splitted[$i_var_for].';'; } } $hortus_file_lines[0] = join("\n", @line_splitted); seek($hortus_file, 0, 0); print $hortus_file @hortus_file_lines; truncate($hortus_file, tell($hortus_file)); close $hortus_file; #print getTimeStamp("log") . " >> DEBUG Filename $trfile, $hortus_file_lines[0]\n"; } my ( $unit, $unittype, $sdpathgd ) = getUnitName($trfile); #print getTimeStamp("log") . " >> Unit $unit - Filename $trfile\n"; if ( !-d "$path/log" ) { make_path "$path/log", { mode => 0755, owner => $truser, group => $gid } or warn getTimeStamp("log") . " >> Failed to create path: $path/log"; } my $outpath = $path . $unit; if ($trfile =~ /home.*home/ && $trfile !~ /Integrity Monitor/) { $outpath = $path . "home/".$unit; } if ( !-d "$outpath/SQL" ) { make_path "$outpath/SQL", { mode => 0755, owner => $truser, group => $gid } or warn getTimeStamp("log") . " >> Failed to create path: $outpath/SQL"; } my $timestamp = getTimeStamp(); my $dest = $outpath . "/" . $filename . "_" . $timestamp . $suffix; if ( !move $trfile, $dest ) { warn getTimeStamp("log") . " >> Move $trfile -> $dest failed: $!"; } else { print getTimeStamp("log") . " >> Moved $trfile -> $dest.\n"; chmod 0666, $dest; my @fname = ($dest); chown $uid, $gid, @fname; if ( ( $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/^G201_ID\d\d\d\d_DT\d\d\d\d\d*$/i or $filename =~ m/^TLP_ID\d\d\d\d_DT\d\d\d\d_\d*$/i or $filename =~ m/^TLP_ID\d\d\d\d_DT\d\d\d\d\d*$/i or $filename =~ m/^GS1_ID\d\d\d\d_DT\d\d\d\d_\d*$/i or $filename =~ m/^GS1_ID\d\d\d\d_DT\d\d\d\d\d*$/i or $filename =~ m/^GS1_ID\d\d\d\d\d_DT\d\d\d\d_\d*$/i or $filename =~ m/^GS1_ID\d\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 or $filename =~ m/^CR1000X_ID\d\d\d\d_DT\d\d\d\d$/i or $filename =~ m/^Hortus_ID\d\d\d\d_DT\d\d\d\d_\d\d\d\d\d\d\d\d\d\d\d\d\d\d$/i or $filename =~ m/^(\d*_|)G301_ID\d\d\d\d_DT\d\d\d\d$/i or $filename =~ m/^GFLOW_ID\d\d\d\d_DT\d\d\d\d_\d*$/i or $filename =~ m/^measurements_\d\d_\d\d_\d\d\d\d__\d\d_\d\d$/i or $filename =~ m/^\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d\d$/i or $filename =~ m/^(\d*-|)health-\d\d\d\d_\d\d_\d\d_\d\d_\d\d_\d\d$/i or $filename =~ m/^(\d*-|)readings-\d\d\d\d_\d\d_\d\d_\d\d_\d\d_\d\d$/i or $filename =~ m/^MesspunktePini_/ or $filename =~ m/^Integrity Monitor / or $filename =~ m/^CO_\d\d\d\d_\d_\d\d\d\d\d\d\d\d_\d\d\d\d\d\d$/i or $filename =~ m/^CO_\d\d\d\d_\d_\d\d\d\d\d\d\d\d_\d\d\d\d\d\d_\d\d\d\d\d\d\d\d\d\d\d\d\d\d$/i or $filename =~ m/^HIRPINIA/ or $filename =~ m/^\d\d\d\d\d\d\d_\d\d\d\d-\d\d-\d\d_\d\d-\d\d-\d\d_\d.log$/i ) and ( $unit ne 'ID9999' ) and ( $truser ne 'corra' ) #and ( $unit ne 'ID0008' ) ) { print getTimeStamp("log") . " >> Sender user $truser: load data into DB.\n"; unless ( fork() ) { setgid($gid); setuid($uid); $ENV{"HOME"} = 'home/' . $truser; if ( $unittype eq 'GFLOW' ) { exec( $scriptpath . "gflowScript.py \"$dest\" >> /home/$truser/log/loadgflow.log 2>&1" ); } elsif ( $unittype eq 'NESA' ) { exec( $scriptpath . "nesaScript.py \"$dest\" >> /home/$truser/log/loadnesa.log 2>&1" ); } elsif ( $unittype eq 'SISGEO' ) { exec( $scriptpath . "sisgeoLoadScript.py \"$dest\" >> /home/$truser/log/loadsisgeo.log 2>&1"); } elsif ($unittype eq 'STAZIONETOTALE'){ #print getTimeStamp("log") . " >> DEBUG file STAZIONETOTALE\n"; exec( $scriptpath . "TS_PiniScript.py \"$dest\" >> /home/$truser/log/loadTS.log 2>&1"); } elsif ( defined $sdpathgd and ($sdpathgd =~ m'/modb/GD' or $sdpathgd =~ m'/dsas/GD') ){ #print getTimeStamp("log") . " >> DEBUG file GD e modb\n"; exec( $scriptpath."loadCSVModbGDLora.py \"$dest\" >> /home/$truser/log/loadgdmodblora.log 2>&1"); } elsif( $unittype eq 'SOROTECPINI' ){ exec( $scriptpath . "sorotecPini.py \"$dest\" >> /home/$truser/log/loadSorotecPini.log 2>&1"); } elsif($unittype eq 'HIRPINIA'){ exec( $scriptpath . "hirpiniaLoadScript.py \"$dest\" >> /home/$truser/log/loadHirpinia.log 2>&1"); } elsif($unittype eq 'VULINK'){ exec( $scriptpath . "vulinkScript.py \"$dest\" >> /home/$truser/log/loadVulink.log 2>&1"); } else { if (defined $stop_elab) { if ($stop_elab == 1) { print getTimeStamp("log") . " >> DEBUG 1 stop_elab 1\n"; #exec( $scriptpath # . "LoadCSVData.pl -f \"$dest\" -s \"$outpath/SQL/$filename" # . "_" # . "$timestamp.sql\" -d $truser >> /home/$truser/log/loadcsvdata.log 2>&1" #); 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 $insert_sth = $dbh2->prepare("INSERT IGNORE INTO elaborazioni_stoppate (type, command, truser) VALUES (0,?,?)"); my $string_to_insert = $scriptpath. "LoadCSVData.pl -f \"$dest\" -s \"$outpath/SQL/$filename". "_". "$timestamp.sql\" -d $truser >> /home/$truser/log/loadcsvdata.log 2>&1"; print getTimeStamp("log") . " >> DEBUG 1 $string_to_insert\n"; $insert_sth->execute($string_to_insert, $truser); $insert_sth->finish; $dbh2->disconnect; } elsif ($stop_elab == 0) { print getTimeStamp("log") . " >> DEBUG 1 stop_elab 0\n"; exec( $scriptpath . "LoadCSVData.pl -f \"$dest\" -s \"$outpath/SQL/$filename" . "_" . "$timestamp.sql\" -d $truser >> /home/$truser/log/loadcsvdata.log 2>&1" ); } else { print getTimeStamp("log") . " >> DEBUG 1 else\n"; exec( $scriptpath . "LoadCSVData.pl -f \"$dest\" -s \"$outpath/SQL/$filename" . "_" . "$timestamp.sql\" -d $truser >> /home/$truser/log/loadcsvdata.log 2>&1" ); } } else { print getTimeStamp("log") . " >> DEBUG 1 pre-else\n"; #print getTimeStamp("log") . " >> DEBUG $dest\n";#debug exec( $scriptpath . "LoadCSVData.pl -f \"$dest\" -s \"$outpath/SQL/$filename" . "_" . "$timestamp.sql\" -d $truser >> /home/$truser/log/loadcsvdata.log 2>&1" ); } } exit(0); } if ( ( $truser ne 'asega' ) and ( $truser ne 'corra' ) ) { print getTimeStamp("log") . " >> Sender user $truser: duplicate as asega user -> load data into DB.\n"; my $realtruser = $truser; $truser = "asega"; $outpath =~ s/$realtruser/$truser/; my ( $login, $pass, $uid, $gid ) = getpwnam($truser) or warn getTimeStamp("log") . " >> $truser not in passwd file.\n"; unless ( fork() ) { setgid($gid); setuid($uid); $ENV{"HOME"} = 'home/' . $truser; if ( defined $sdpathgd and ($sdpathgd =~ m'/modb/GD' or $sdpathgd =~ m'/dsas/GD') ){ #print getTimeStamp("log") . " >> DEBUG file GD e modb duplica\n";#debug } else { if (defined $stop_elab) { if ($stop_elab == 1) { print getTimeStamp("log") . " >> DEBUG 2 stop_elab 1\n"; #exec( $scriptpath # . "LoadCSVData.pl -f \"$dest\" -s \"$outpath/SQL/$filename" # . "_" # . "$timestamp.sql\" -d $truser >> /home/$truser/log/loadcsvdata.log 2>&1" #); 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 $insert_sth = $dbh2->prepare("INSERT IGNORE INTO elaborazioni_stoppate (type, command, truser) VALUES (0,?,?)"); my $string_to_insert = $scriptpath. "LoadCSVData.pl -f \"$dest\" -s \"$outpath/SQL/$filename". "_". "$timestamp.sql\" -d $truser >> /home/$truser/log/loadcsvdata.log 2>&1"; print getTimeStamp("log") . " >> DEBUG 2 $string_to_insert\n"; $insert_sth->execute($string_to_insert, $truser); $insert_sth->finish; $dbh2->disconnect; } elsif ($stop_elab == 0) { print getTimeStamp("log") . " >> DEBUG 2 stop_elab 0\n"; exec( $scriptpath . "LoadCSVData.pl -f \"$dest\" -s \"$outpath/SQL/$filename" . "_" . "$timestamp.sql\" -d $truser >> /home/$truser/log/loadcsvdata.log 2>&1" ); } else { print getTimeStamp("log") . " >> DEBUG 2 else\n"; exec( $scriptpath . "LoadCSVData.pl -f \"$dest\" -s \"$outpath/SQL/$filename" . "_" . "$timestamp.sql\" -d $truser >> /home/$truser/log/loadcsvdata.log 2>&1" ); } } else { print getTimeStamp("log") . " >> DEBUG 2 pre-else\n"; #print getTimeStamp("log") . " >> DEBUG $dest\n";#debug exec( $scriptpath . "LoadCSVData.pl -f \"$dest\" -s \"$outpath/SQL/$filename" . "_" . "$timestamp.sql\" -d $truser >> /home/$truser/log/loadcsvdata.log 2>&1" ); } } exit(0); } } } } } } } exit(0);