• # Un PERL fite fait ....

    Posté par . En réponse au message chmod 777 -R . pour tout le monde !!!!. Évalué à 4.

    Voici un script PERL ecrit a l'arrache.

    En l'adaptant, et en supposant que tu as une sauvegarde, il devrait te sortir d'affaire.

    Attention, il ne génère pas les SUID bits (c'est a dire les Ss sur les droits) . A toi (ou quelqu'un d'autre) de modifier le code.

    Aparamment il ne gère pas non plus les fichiers cachés (.profile, etc ...).

    A tester avant d'utiliser!!! Je ne peux être tenu responsable d'un quelconque dysfonctionnement lié a l'utilisation de ce script.

    Licence: GPL.

    Vous êtes fortement encouragés à l'améliorer.

    PS: L'indentation a sauté lors de l'affichage.


    -----------------------------------------------------------------------------------
    #!/usr/bin/perl -w

    sub convert_rights
    {
    my $Droits=shift;

    my @tab=split(//,$Droits);
    my $Count=0;
    my $Rights=0;
    foreach(@tab) {
    #print ("Droit:$_\n");
    SWITCH: {
    if($Count==0) {
    last SWITCH;
    }
    if($Count==1) {
    if("$_" eq 'r') {
    $Rights=$Rights+0400;
    }
    last SWITCH;
    }
    if($Count==2) {
    if("$_" eq 'w') {
    $Rights=$Rights+0200;
    }
    last SWITCH;
    }
    if($Count==3) {
    if("$_" eq 'x') {
    $Rights=$Rights+0100;
    }
    last SWITCH;
    }
    if($Count==4) {
    if("$_" eq 'r') {
    $Rights=$Rights+040;
    }
    last SWITCH;
    }
    if($Count==5) {
    if("$_" eq 'w') {
    $Rights=$Rights+020;
    }
    last SWITCH;
    }
    if($Count==6) {
    if("$_" eq 'x') {
    $Rights=$Rights+010;
    }
    last SWITCH;
    }
    if($Count==7) {
    if("$_" eq 'r') {
    $Rights=$Rights+04;
    }
    last SWITCH;
    }
    if($Count==8) {
    if("$_" eq 'w') {
    $Rights=$Rights+02;
    }
    last SWITCH;
    }
    if($Count==9) {
    if("$_" eq 'x') {
    $Rights=$Rights+01;
    }
    last SWITCH;
    }
    }

    $Count++;
    }

    return $Rights;

    }
    sub changemod
    {
    my $Droits=shift;
    my $Fichier=shift;

    print "chmod sur $Fichier, nouveaux droits $Droits\n";
    my $Rights= convert_rights($Droits);
    printf("Attribution des droits %o sur $Fichier\n",$Rights);
    unless(chmod $Rights,$Fichier) {
    print STDERR " ->Changement de droit sur $Fichier impossible \n";

    }
    else {
    print " -->Changement de droits sur $Fichier OK\n";
    }

    }

    sub change_rights
    {
    my $Line=shift;
    chomp $Line;
    #print("Line: $Line\n");

    if ($Line) {
    @L=split(/\s+/,$Line);
    #print ("Line2: $L[0]\n");
    #print ("Line3: $L[8]\n");
    if (-f $L[8]) {
    #print ("$L[8]\n");
    changemod($L[0],$L[8]);
    }
    else {
    print STDERR "Le fichier $L[8] n'existe pas(plus) sur cette machine \n";
    }
    }
    }

    # Recuperation de la liste des fichiers
    $Sauvegarde=$ARGV[0];

    open (COMMAND, "tar -tvf $Sauvegarde |") or die "Impossible d'ouvritr le fichioer $Sauvegarde\n$!";

    while (<COMMAND>) {
    change_rights($_);
    }

    close(COMMAND);