list-config_modif_quota.pl

#!/usr/bin/perl -w
#
# list-config_modif_quota.pl
#
# Catherine.Balleydier@inpg.fr
#
# maj : 23/09/16
#
########################################################################
# 
#   modifier les quotas des archives  $nvquota = "4000"
#   supprimer les quotas des archives  $nvquota = "NON"
#
########################################################################
#
use strict;
use warnings;
use File::Copy;
 
my $REProbot = "/home/sympa/list_data/" ;
my $REP ;
my $robot ;
my $fichier ;
my @CONFIG ;
my @liste ;
my $entree ;
my $nvfichier ;
my $LIGNE ;
#my $nvquota = "4000";
my $nvquota = "NON";
#
#  date
#
my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
my $marque = (1900+$year)."_".($mon+1)."_"."$mday"."_"."$hour"."_"."$min" ;
 
#
#  lister les robots  du repertoire /home/sympa/list_data
#
opendir(DIR, $REProbot) || die "Impossible de lire $REProbot : $!\n";
my @robots = grep { /^[^\.]/ && -r "$REProbot/$_" } readdir(DIR);
closedir(DIR);
 
 
#
# traiter pour chaque robot
# 
ETIQ : foreach $robot (@robots)
{
  if ( $robot =~ /blacklist/ ) { next ETIQ ;}
  $REP = "$REProbot"."$robot"."/";
#
#  lister le contenu du repertoire /home/sympa/list_data/robot
#
  opendir(DIR, $REP) || die "Impossible de lire $REP : $!\n";
  @liste = grep { /^[^\.]/ && -r "$REP/$_" } readdir(DIR);
  closedir(DIR);
 
#
# traiter pour chaque liste le fichier config
#
  foreach $entree (@liste)
  {
#  
# ouverture du fichier config
#
    $fichier = "$REP"."$entree"."/config" ; 
    copy ("$fichier", "$fichier"."."."$marque") ;
    open (FICH,"$fichier") ||die "probleme fichier config";
    @CONFIG = <FICH> ;
    close (FICH); 
 
    $nvfichier  = "$REP"."$entree"."/nvconfig" ;
    open (NVFICH,">$nvfichier") ||die "probleme nvfichier";
#
#  chercher les quotas 
#
   foreach $LIGNE (@CONFIG)
   {
      if ( $LIGNE =~ /quota/)
      {
         if ( $nvquota ne "NON")
         {
            $LIGNE = "quota "."$nvquota" ;
            chomp $LIGNE ;
	    print NVFICH "$LIGNE\n" ;
         }
      }
      else
      {
        chomp $LIGNE ;
        print NVFICH "$LIGNE\n" ;
      }
   }
   close (NVFICH) ;
   rename ("$nvfichier","$fichier") ;
   chown "503" , "503", "$fichier" ;
 }
}