# Mise à jour des répertoires Novell / NT # Paramètres de bases! $base="E:\\NTBASE\\Base"; $novell="D:\\NOVELL\\Source"; $nt="E:\\WINDOWSNT\\Destination"; system "cls"; printf("RECHERCHE DES FICHIERS SUPPRIMES/MODIFIES/NOUUEAUX SUR NOVELL\n"); opendir(REP, $novell) || ( warn "SOURCE Erreur:$! \n", exit ); while ( ($user = readdir( REP )) ne "" ) { next if $user eq '.'; next if $user eq '..'; # print ( "- REPERTOIRE DE $user\n"); opendir( REP2, "$novell\\$user" )|| ( warn "User $user Erreur:$! \n", next ); ( -d "$base\\$user" ) || mkdir "$base\\$user",777 ; # Création du répertoire NT si inexistant! if ( ! -d "$nt\\$user" ) { mkdir "$nt\\$user",777 ; print ( "*** CREATION DE $nt\\$user AFFECTER LES DROITS CORRECTS ***\n"); }; # Transfert de l'ancienne Liste de fichiers ( ! -f "$base\\$user\\$user".".O1" ) || unlink ("$base\\$user\\$user".".O1"); ( ! -f "$base\\$user\\$user".".L1" ) || rename ("$base\\$user\\$user".".L1", "$base\\$user\\$user".".O1"); # Création de la nouvelle Liste de fichiers open( LISTE1, ">$base\\$user\\$user".".L1" ); $n1=0; while ( ($fic = readdir( REP2 )) ne "" ) { next if -d "$novell\\$user\\$fic"; next if $fic eq '.'; next if $fic eq '..'; # Récupération des informations du fichier ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)=stat("$novell\\$user\\$fic"); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($mtime); $mon++; # Pour Information # $d =localtime($mtime); # print( "Modification $d\n" ); # $d =localtime($ctime); # print( "Création $d\n" ); # Formattage des données $t1fic[$n1]="$fic"; $t1fic[$n1]=~tr/a-z/A-Z/; $t1date[$n1]=sprintf("%2d%2d%2d%2d%2d%2d","$year","$mon","$mday","$hour","$min","$sec"); $t1date[$n1]=~tr/ /0/; $t1taille[$n1]="$size"; # print("$t1fic[$n1]\t$t1date[$n1]\t$t1taille[$n1]\n"); # Ajout dans la liste select(LISTE1); print( "$t1fic[$n1]"."|"."$t1date[$n1]"."|"."$t1taille[$n1]\n"); $n1++; select(STDOUT); } ; close( LISTE1); # Chargement de la liste Précédente (si elle existe) if ( -f "$base\\$user\\$user".".O1" ) { $n2=0; open( LISTE2, "\<$base\\$user\\$user".".O1" ) || ( warn "Erreur lecture", exit ); while () # lit une ligne dans $_ { chop($_); $x=index("$_","|"); $t2fic[$n2]=substr("$_",0,$x); if ( $t2fic[$n2] ne "" ) { $y=index("$_","|",$x+1); $t2date[$n2]=substr("$_",$x+1,$y-$x-1); $t2taille[$n2]=substr("$_",$y+1); # print("$t2fic[$n2]\t$t2date[$n2]\t$t2taille[$n2]\n"); $n2++; }; } ; close( LISTE2); # Détermination des fichiers Nouveaux(N), Modifiés(M), Supprimés(S) à partir des tableaux open( M1, ">$base\\$user\\$user".".M1" ); open( S1, ">$base\\$user\\$user".".S1" ); open( N1, ">$base\\$user\\$user".".N1" ); for ($i = 0; $i < $n2; $i++) { $OK="false"; for ($j = 0; $j < $n1; $j++) { # print ("$i $t2fic[$i]"."|$j $t1fic[$j]\n" ); if ( $t2fic[$i] eq $t1fic[$j] ) { $OK="true"; if ( ($t2date[$i] < $t1date[$j]) || ($t2taille[$i] != $t1taille[$j]) ) { select(M1); print( "$t1fic[$j]"."|"."$t1date[$j]"."|"."$t1taille[$j]\n"); select(STDOUT); print ( "- MODIFIE: $t1fic[$j]\n"); }; }; }; if ( "$OK" eq "false" ) { select(S1); print( "$t2fic[$i]"."|"."$t2date[$i]"."|"."$t2taille[$i]\n"); select(STDOUT); print ( "- SUPPRIME: $t2fic[$i]\n"); }; }; # Recherche des Nouveaux fichiers (Messages) for ($j = 0; $j < $n1; $j++) { $OK="false"; for ($i = 0; $i < $n2; $i++) { # print ("$i $t2fic[$i]"."|$j $t1fic[$j]\n" ); if ( $t2fic[$i] eq $t1fic[$j] ) { $OK="true"; }; }; if ( "$OK" eq "false" ) { select(N1); print( "$t1fic[$j]"."|"."$t1date[$j]"."|"."$t1taille[$j]\n"); select(STDOUT); print ( "- NOUVEAU: $t1fic[$j]\n"); }; }; close(N1); close(S1); close(M1); }; closedir(REP2); print ( "- REPERTOIRE DE $user - Messages ($n1) J-1 ($n2)\n"); } ; closedir(REP); #--------------------------------------------------------------------------------------- printf("RECHERCHE DES FICHIERS SUPPRIMES/MODIFIES/NOUUEAUX SUR NT\n"); opendir(REP, $nt) || ( warn "Erreur Source", exit ); while ( ($user = readdir( REP )) ne "" ) { next if $user eq '.'; next if $user eq '..'; # print ( "- REPERTOIRE DE $user\n"); opendir( REP2, "$nt\\$user" )|| ( warn "User $user Erreur:$! \n", next ); ( -d "$base\\$user" ) || mkdir "$base\\$user",777; # Création du répertoire Novell si inexistant! if ( ! -d "$novell\\$user" ) { mkdir "$novell\\$user",777; print ( "*** CREATION DE $novell\\$user AFFECTER LES DROITS CORRECTS ***\n"); }; ( ! -f "$base\\$user\\$user".".O2" ) || unlink ("$base\\$user\\$user".".O2"); ( ! -f "$base\\$user\\$user".".L2" ) || rename ("$base\\$user\\$user".".L2", "$base\\$user\\$user".".O2"); open( LISTE1, ">$base\\$user\\$user".".L2" ); $n1=0; while ( ($fic = readdir( REP2 )) ne "" ) { next if -d "$nt\\$user\\$fic"; next if $fic eq '.'; next if $fic eq '..'; # Récupération des informations du fichier ($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$mtime,$ctime,$blksize,$blocks)=stat("$nt\\$user\\$fic"); ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime($mtime); $mon++; # $d =localtime($mtime); # print( "Modification $d\n" ); # $d =localtime($ctime); # print( "Création $d\n" ); # Affichage du fichier $t1fic[$n1]="$fic"; $t1fic[$n1]=~tr/a-z/A-Z/; $t1date[$n1]=sprintf("%2d%2d%2d%2d%2d%2d","$year","$mon","$mday","$hour","$min","$sec"); $t1date[$n1]=~tr/ /0/; $t1taille[$n1]="$size"; # print("$t1fic[$n1]\t$t1date[$n1]\t$t1taille[$n1]\n"); # Mise à jour du fichier select(LISTE1); print( "$t1fic[$n1]"."|"."$t1date[$n1]"."|"."$t1taille[$n1]\n"); $n1++; select(STDOUT); } ; close( LISTE1); if ( -f "$base\\$user\\$user".".O2" ) { # print ( "Liste precedente des fichiers\n" ); $n2=0; open( LISTE2, "\<$base\\$user\\$user".".O2" ) || ( warn "Erreur lecture", exit ); while () # lit une ligne dans $_ { chop($_); $x=index("$_","|"); $t2fic[$n2]=substr("$_",0,$x); if ( $t2fic[$n2] ne "" ) { $y=index("$_","|",$x+1); $t2date[$n2]=substr("$_",$x+1,$y-$x-1); $t2taille[$n2]=substr("$_",$y+1); # print("$t2fic[$n2]\t$t2date[$n2]\t$t2taille[$n2]\n"); $n2++; }; } ; close( LISTE2); open( M2, ">$base\\$user\\$user".".M2" ); open( S2, ">$base\\$user\\$user".".S2" ); open( N2, ">$base\\$user\\$user".".N2" ); for ($i = 0; $i < $n2; $i++) { $OK="false"; for ($j = 0; $j < $n1; $j++) { # print ("$i $t2fic[$i]"."|$j $t1fic[$j]\n" ); if ( $t2fic[$i] eq $t1fic[$j] ) { $OK="True"; if ( ($t2date[$i] < $t1date[$j]) || ($t2taille[$i] != $t1taille[$j]) ) { select(M2); print( "$t1fic[$j]"."|"."$t1date[$j]"."|"."$t1taille[$j]\n"); select(STDOUT); print ( "- MODIFIE: $t1fic[$j]\n"); }; }; }; if ( "$OK" eq "false" ) { select(S2); print( "$t2fic[$i]"."|"."$t2date[$i]"."|"."$t2taille[$i]\n"); select(STDOUT); print ( "- SUPPRIME: $t2fic[$i]\n"); }; }; # Recherche des Nouveaux fichiers (Messages) for ($j = 0; $j < $n1; $j++) { $OK="false"; for ($i = 0; $i < $n2; $i++) { # print ("$i $t2fic[$i]"."|$j $t1fic[$j]\n" ); if ( $t2fic[$i] eq $t1fic[$j] ) { $OK="true"; }; }; if ( "$OK" eq "false" ) { select(N2); print( "$t1fic[$j]"."|"."$t1date[$j]"."|"."$t1taille[$j]\n"); select(STDOUT); print ( "- NOUVEAU: $t1fic[$j]\n"); }; }; close(N2); close(S2); close(M2); }; closedir(REP2); print ( "- REPERTOIRE DE $user - Messages ($n1) J-1 ($n2)\n"); } ; closedir(REP); #--------------------------------------------------------------------------------------- # Boucle principale de transfert des fichiers printf("TRAITEMENT DES TRANSFERTS\n"); opendir(REP, $base) || ( warn "BASE Erreur:$! \n", exit ); while ( ($user = readdir( REP )) ne "" ) { next if $user eq '.'; next if $user eq '..'; # print ( "- REPERTOIRE DE $user "); # Gestion des fichiers supprimés $n1=0; open( LISTE1, "\<$base\\$user\\$user".".S1" ) || ( warn "Erreur lecture", exit ); while () # lit une ligne dans $_ { chop($_); $x=index("$_","|"); $t1fic[$n1]=substr("$_",0,$x); if ( $t1fic[$n1] ne "" ) { $y=index("$_","|",$x+1); $t1date[$n1]=substr("$_",$x+1,$y-$x-1); $t1taille[$n1]=substr("$_",$y+1); # print("$t1fic[$n1]\t$t1date[$n1]\t$t1taille[$n1]\n"); $n1++; }; } ; close( LISTE1); $n2=0; open( LISTE2, "\<$base\\$user\\$user".".S2" ) || ( warn "Erreur lecture", exit ); while () # lit une ligne dans $_ { chop($_); $x=index("$_","|"); $t2fic[$n2]=substr("$_",0,$x); if ( $t2fic[$n2] ne "" ) { $y=index("$_","|",$x+1); $t2date[$n2]=substr("$_",$x+1,$y-$x-1); $t2taille[$n2]=substr("$_",$y+1); # print("$t2fic[$n2]\t$t2date[$n2]\t$t2taille[$n2]\n"); $n2++; }; } ; close( LISTE2); if ( $n1 > 0 ) { # printf ( "Novell Is Master for $user\n" ); for ($i = 0; $i < $n1; $i++) { # printf ("Suppression de $nt\\$user\\$t1fic[$i]\n"); unlink ("$nt\\$user\\$t1fic[$i]"); $ordre="type $base\\$user\\$user.L2 \| find /v \"$t1fic[$i]\|\" >$base\\$user\\$user.TMP"; system $ordre; unlink ("$base\\$user\\$user".".L2"); rename ("$base\\$user\\$user".".TMP", "$base\\$user\\$user".".L2"); }; }; if ( $n2 > 0 ) { # printf( "NT Is Master for $user\n"); for ($j = 0; $j < $n2; $j++) { # printf ("Suppression de $novell\\$user\\$t2fic[$j]\n"); unlink ("$novell\\$user\\$t2fic[$j]"); $ordre="type $base\\$user\\$user.L1 \| find /v \"$t2fic[$j]\|\" >$base\\$user\\$user.TMP"; system $ordre; unlink ("$base\\$user\\$user".".L1"); rename ("$base\\$user\\$user".".TMP", "$base\\$user\\$user".".L1"); }; }; $sup=$n1+$n2; # Gestion des Nouveaux fichiers $n1=0; open( LISTE1, "\<$base\\$user\\$user".".N1" ) || ( warn "Erreur lecture", exit ); while () # lit une ligne dans $_ { chop($_); $x=index("$_","|"); $t1fic[$n1]=substr("$_",0,$x); if ( $t1fic[$n1] ne "" ) { $y=index("$_","|",$x+1); $t1date[$n1]=substr("$_",$x+1,$y-$x-1); $t1taille[$n1]=substr("$_",$y+1); # print("$t1fic[$n1]\t$t1date[$n1]\t$t1taille[$n1]\n"); $n1++; }; } ; close( LISTE1); if ( $n1 > 0 ) { open( LISTE1, ">>$base\\$user\\$user".".L2" ); for ($i = 0; $i < $n1; $i++) { # printf ("Copie de $novell\\$user\\$t1fic[$i]\n"); $ordre="COPY $novell\\$user\\$t1fic[$i] $nt\\$user\\$t1fic[$i] >NUL:"; system $ordre; # Mise à jour de l'heure correcte sur le fichier! $d="19".substr($t1date[$i],0,2)." ".substr($t1date[$i],2,2)." " .substr($t1date[$i],4,2)." ".substr($t1date[$i],6,2)." " .substr($t1date[$i],8,2)." ".substr($t1date[$i],10,2); $ordre="touch /t $d $nt\\$user\\$t1fic[$i]"; select(LISTE1); print( "$t1fic[$i]"."|"."$t1date[$i]"."|"."$t1taille[$i]\n"); select(STDOUT); } ; close( LISTE1); }; $n2=0; open( LISTE2, "\<$base\\$user\\$user".".N2" ) || ( warn "Erreur lecture", exit ); while () # lit une ligne dans $_ { chop($_); $x=index("$_","|"); $t2fic[$n2]=substr("$_",0,$x); if ( $t2fic[$n2] ne "" ) { $y=index("$_","|",$x+1); $t2date[$n2]=substr("$_",$x+1,$y-$x-1); $t2taille[$n2]=substr("$_",$y+1); # print("$t2fic[$n2]\t$t2date[$n2]\t$t2taille[$n2]\n"); $n2++; }; } ; close( LISTE2); if ( $n2 > 0 ) { open( LISTE2, ">>$base\\$user\\$user".".L1" ); for ($j = 0; $j < $n2; $j++) { # printf ("Copie de $nt\\$user\\$t2fic[$j]\n"); $ordre="COPY $nt\\$user\\$t2fic[$j] $novell\\$user\\$t2fic[$j] >NUL:"; system $ordre; # Mise à jour de l'heure correcte sur le fichier! $d="19".substr($t2date[$j],0,2)." ".substr($t2date[$j],2,2)." " .substr($t2date[$j],4,2)." ".substr($t2date[$j],6,2)." " .substr($t2date[$j],8,2)." ".substr($t2date[$j],10,2); $ordre="touch /t $d $novell\\$user\\$t2fic[$j]"; select(LISTE2); print( "$t2fic[$j]"."|"."$t2date[$j]"."|"."$t2taille[$j]\n"); select(STDOUT); } ; close( LISTE2); }; $nou=$n1+$n2; # Gestion des fichiers modifiés $n1=0; open( LISTE1, "\<$base\\$user\\$user".".M1" ) || ( warn "Erreur lecture", exit ); while () # lit une ligne dans $_ { chop($_); $x=index("$_","|"); $t1fic[$n1]=substr("$_",0,$x); if ( $t1fic[$n1] ne "" ) { $y=index("$_","|",$x+1); $t1date[$n1]=substr("$_",$x+1,$y-$x-1); $t1taille[$n1]=substr("$_",$y+1); # print("$t1fic[$n1]\t$t1date[$n1]\t$t1taille[$n1]\n"); $n1++; }; } ; close( LISTE1); $n2=0; open( LISTE2, "\<$base\\$user\\$user".".M2" ) || ( warn "Erreur lecture", exit ); while () # lit une ligne dans $_ { chop($_); $x=index("$_","|"); $t2fic[$n2]=substr("$_",0,$x); if ( $t2fic[$n2] ne "" ) { $y=index("$_","|",$x+1); $t2date[$n2]=substr("$_",$x+1,$y-$x-1); $t2taille[$n2]=substr("$_",$y+1); # print("$t2fic[$n2]\t$t2date[$n2]\t$t2taille[$n2]\n"); $n2++; }; } ; close( LISTE2); for ($i = 0; $i < $n1; $i++) { for ($j = 0; $j < $n2; $j++) { if ( $t1fic[$i] eq $t2fic[$j] ) { if ($t1date[$i] < $t2date[$j]) { $t1fic[$i]="-ANNULE-"; } else { $t2fic[$j]="-ANNULE-"; }; }; }; }; if ( $n1 > 0 ) { for ($i = 0; $i < $n1; $i++) { if ( $t1fic[$i] ne "-ANNULE-" ) { # printf ("Copie de $novell\\$user\\$t1fic[$i]\n"); $ordre="COPY $novell\\$user\\$t1fic[$i] $nt\\$user\\$t1fic[$i] >NUL:"; system $ordre; # Mise à jour de l'heure correcte sur le fichier! $d="19".substr($t1date[$i],0,2)." ".substr($t1date[$i],2,2)." " .substr($t1date[$i],4,2)." ".substr($t1date[$i],6,2)." " .substr($t1date[$i],8,2)." ".substr($t1date[$i],10,2); $ordre="touch /t $d $nt\\$user\\$t1fic[$i]"; # Suppression de l'ancienne version dans la base $ordre="type $base\\$user\\$user.L2 \| find /v \"$t1fic[$i]\|\" >$base\\$user\\$user.TMP"; system $ordre; unlink ("$base\\$user\\$user".".L2"); rename ("$base\\$user\\$user".".TMP", "$base\\$user\\$user".".L2"); # Ajout de la nouvelle version! open( LISTE1, ">>$base\\$user\\$user".".L2" ); select(LISTE1); print( "$t1fic[$i]"."|"."$t1date[$i]"."|"."$t1taille[$i]\n"); select(STDOUT); close( LISTE1); }; } ; }; if ( $n2 > 0 ) { for ($j = 0; $j < $n2; $j++) { if ( $t2fic[$j] ne "-ANNULE-" ) { # printf ("Copie de $nt\\$user\\$t2fic[$j]\n"); $ordre="COPY $nt\\$user\\$t2fic[$j] $novell\\$user\\$t2fic[$j] >NUL:"; system $ordre; # Mise à jour de l'heure correcte sur le fichier! $d="19".substr($t2date[$j],0,2)." ".substr($t2date[$j],2,2)." " .substr($t2date[$j],4,2)." ".substr($t2date[$j],6,2)." " .substr($t2date[$j],8,2)." ".substr($t2date[$j],10,2); $ordre="touch /t $d $novell\\$user\\$t2fic[$j]"; # Suppression de l'ancienne version dans la base $ordre="type $base\\$user\\$user.L1 \| find /v \"$t2fic[$j]\|\" >$base\\$user\\$user.TMP"; system $ordre; unlink ("$base\\$user\\$user".".L1"); rename ("$base\\$user\\$user".".TMP", "$base\\$user\\$user".".L1"); # Ajout de la nouvelle version! open( LISTE2, ">>$base\\$user\\$user".".L1" ); select(LISTE2); print( "$t2fic[$j]"."|"."$t2date[$j]"."|"."$t2taille[$j]\n"); select(STDOUT); close( LISTE2); } ; }; }; $mod=$n1+$n2; print ( "- REPERTOIRE DE $user - SUPPRIMES($sup) NOUVEAUX($nou) MODIFIES ($mod)\n"); } ; close (REP); exit;