[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/se3master/usr/share/se3/scripts/ -> clean_homes.sh (source)

   1  #!/bin/bash
   2  
   3  # $Id: clean_homes.sh 7441 2012-10-20 00:40:41Z keyser $
   4  # Script destine a gerer les comptes orphelins globalement en remplacement  de mv_Trash_Home.sh, delHome.pl 
   5  # Auteur: Franck Molle
   6  # Derniere modification: 10/2011
   7  
   8  
   9  ### recup params 
  10  # /usr/share/se3/includes/config.inc.sh -l ----> marche pas avec le getops !!!
  11  . /etc/se3/config_l.cache.sh
  12  
  13  usage()
  14  {
  15      echo "script permettant le nettoyage des homes et / ou /var/se3 suite bascule annuelle" 
  16      echo "usage: $0 -c -d -o -m -t -s -v -h"
  17      echo "       -c :  clean - supressions vieux fichiers sans proprio"
  18      echo "       -d :  del - suppression des homes orphelins"
  19      echo "       -m :  move - deplacement des homes orphelins dans /home/admin/_trash_user"
  20      echo "       -s :  shedule  - lancement en tache at le soir "
  21      echo "       -o :  only - utile pour les maj"
  22      echo "       -t :  move only - deplacement vieux fichiers de home uniquement vers /home/admin/Trash_users"
  23      echo "       -v :  varse3 : scanne de la partition /var/se3 pour suppresion fichiers obsoletes"
  24      echo "       -h :  Show this help"
  25      exit $1
  26  }
  27  
  28  
  29  ldap_status()
  30  {
  31  
  32  if [ ! -e /var/run/slapd/slapd.pid ];then
  33      echo "ERREUR: Le serveur ldap ne semble pas fonctionner"
  34      echo "Interuption du script"
  35      exit 1
  36  fi
  37  }
  38  
  39  
  40  if [ $# -eq "0" ]  # Script appele sans argument?
  41  then
  42    echo "option incorrecte"
  43    usage 1 
  44  fi
  45  
  46  
  47  
  48  
  49  
  50  
  51  unset CLEAN DELETE ONLY SHEDUL MOVE TRASH VARSE3
  52  
  53  VERSBOSE=0
  54  while getopts ":cdostmvh" cmd
  55  do
  56      case $cmd in    
  57      c) CLEAN=1 
  58      opt="c" ;;
  59      d) DELETE=1 ;;
  60      o) ONLY=1 
  61      opt="o" ;;
  62      s) SHEDUL=1 ;;
  63      t) TRASH=1 ;;
  64      v) VARSE3=1
  65      opt="v";;
  66      m) MOVE=1 
  67      opt="m" ;;
  68      h) usage 0 ;;
  69      \?) echo "bad option!"
  70      usage 1 ;;
  71      *) echo "bad option!"
  72      usage 1 ;;
  73      esac
  74  done
  75  
  76  ### recup params 
  77  # . /usr/share/se3/includes/config.inc.sh -mlv
  78  
  79  
  80  if [ "$TRASH" = "1" ]; then 
  81    rm -rf /home/admin/Trash_users
  82  fi
  83  
  84  
  85  
  86  if [ "$SHEDUL" = "1" ]; then 
  87    at_script="/tmp/clean_homes_at.sh"
  88    cat > $at_script <<END
  89  #!/bin/bash
  90  $0 -$opt
  91  END
  92  
  93    chmod 700 $at_script
  94    if [ "$ONLY" = "1" -o "$CLEAN" = "1" ]; then 
  95        at 20:00 -f $at_script
  96    else
  97        at now -f $at_script  
  98    fi
  99    exit 0
 100  fi
 101  
 102  
 103  if [ "$VARSE3" = "1" -o "$CLEAN" = "1" ]; then 
 104      echo "Recherche et suppression vieux fichiers sur le partage Classes"
 105      ldap_status
 106      find /var/se3/Classes/* -nouser -type f -print -exec rm -f "{}" \; 2>/dev/null
 107      find /var/se3/Classes/* -nouser -type d -print -exec rmdir "{}" \; 2>/dev/null
 108  
 109      echo "Recherche et suppression vieux fichiers sur partage Docs"
 110      ldap_status
 111      find /var/se3/Docs/* -nouser -type f -print -exec rm -f "{}" \; 2>/dev/null
 112      find /var/se3/Docs/* -nouser -type d -print -exec rmdir "{}" \; 2>/dev/null
 113  
 114      echo "Recherche et suppression vieux fichiers sur partage Progs"
 115      ldap_status
 116      find /var/se3/Progs/* -nouser -type f -print -exec rm -f "{}" \; 2>/dev/null
 117      find /var/se3/Progs/* -nouser -type d -print -exec rmdir "{}" \; 2>/dev/null
 118  
 119      echo "Recherche et suppression vieux fichiers sur partage prof"
 120      ldap_status
 121      find /var/se3/prof/* -nouser -type f -print -exec rm -f "{}" \; 2>/dev/null
 122      find /var/se3/prof/* -nouser -type d -print -exec rmdir "{}" \; 2>/dev/null
 123  fi
 124  
 125  if [ "$ONLY" = "1" -o "$CLEAN" = "1" ]; then 
 126  
 127      if [ -e /var/run/backuppc/BackupPC.pid ]; then
 128      invoke-rc.d backuppc stop
 129      bpc_etat="1"
 130      fi
 131      echo "Recherche et suppression vieux profils XP / Seven"
 132      ldap_status
 133      find /home/profiles/ -maxdepth 1  -type d -nouser -print -exec rm -rf "{}" \;
 134      #    find /home/admin/profiles/ -maxdepth 1  -type d -nouser -print -exec rm -rf "{}" \;
 135      #     find /home/ -maxdepth 4 -nouser -print -exec rm -rf "{}" \; 2>/dev/null
 136  
 137  
 138      if [ "$CLEAN" = "1" ]; then 
 139      echo "Recherche et suppression vieux fichiers /home/admin/Trash_users"
 140      find /home/admin/Trash_users -name _Trash_[0-9_]* -print -exec rm -rf "{}" \; 2>/dev/null
 141      
 142      fi
 143  
 144      LADATE=$(date +%d-%m-%Y)
 145      dest=/home/admin/Trash_users/_Trash_$LADATE
 146  
 147      cpt=0
 148      cd /home
 149      ldap_status
 150      ls /home | while read A
 151      do
 152      if [ -d "/home/$A"  -a ! -L /home/$A ]; then
 153          if [ ! -z "$(echo "$A" | grep -e "_Trash_[0-9_]*")" ]; then
 154              # permet de corriger une erreur de quota en cas d'uid re-attribue
 155              echo "Deplacement du dossier Trash $A dans /home/admin/ "
 156              mkdir -p /home/admin/Trash_users/
 157              chown admin:admins /home/admin/Trash_users/
 158              mv /home/$A /home/admin/Trash_users/
 159              chown -R admin:admins /home/admin/Trash_users/$A 
 160          else 
 161              if [ "$A" != "templates" -a "$A" != "netlogon" -a "$A" != "admin" -a "$A" != "samba" -a "$A" != "sauvegarde" -a "$A" != "profiles" ]; then
 162                  if [ -z "$(getfacl $A 2>/dev/null|grep owner|grep $A)"  ]; then
 163                
 164                      echo "$A n'est pas proprio de son Home... mise en $dest."
 165                      if [ "$cpt" = "0" ]; then
 166                          mkdir -p /home/admin/Trash_users
 167                          chown admin:admins /home/admin/Trash_users
 168                          mkdir -p ${dest}
 169                      fi
 170                      mv /home/$A $dest/
 171                      rm -rf /home/profiles/$A
 172                      chown -R admin:admins $dest/$A
 173                      cpt=1
 174                  
 175                  fi  
 176              
 177              fi
 178          fi
 179      fi
 180      
 181      
 182      
 183      done
 184  
 185      
 186  
 187      if [ "$bpc_etat" = "1" ]; then
 188          invoke-rc.d backuppc start
 189      fi
 190  
 191  
 192  
 193  fi
 194  if  [ "$DELETE" = "1" -o "$MOVE" = "1" ]; then
 195      dest=/home/admin/Trash_users/_Trash_$(date +%Y%m%d_%H%M%S)
 196      fich=/var/www/se3/Admin/mv_Trash_$(date +%Y%m%d%H%M%S)
 197      cpt=0
 198         
 199      echo "Parcours de la Corbeille...<br />"
 200      ldapsearch -xLLL -b ou=Trash,$ldap_base_dn uid | grep "^uid: " | sed -e "s/^uid: //" | while read uid
 201      do
 202      #echo "Controle de $uid"
 203        if [ -d "/home/$uid" ]; then
 204          if [ "$MOVE" = "1" ]; then 
 205          
 206              if [ "$cpt" = "0" ]; then
 207                mkdir -p /home/admin/Trash_users
 208                chown admin:admins /home/admin/Trash_users
 209                mkdir -p ${dest}
 210                if [ "$?" != "0" ]; then
 211                    echo "ERREUR: La creation du dossier ${dest} a echoue."
 212                    exit 1
 213                fi
 214                echo "Deplacement vers ${dest}: <br>"
 215              else
 216                echo ", "|tee -a $fich
 217              fi
 218              echo "$uid"|tee -a $fich
 219              mv /home/$uid ${dest}/
 220              chown -R admin ${dest}/$uid 
 221              rm -f /var/se3/Docs/trombine/$uid.* 
 222  #            echo "mv /home/$uid ${dest}/ <br>"
 223  
 224              cpt=$(($cpt+1))
 225          else
 226              echo  "Suppression de /home/$uid <br>"
 227              rm -fr /home/$uid 
 228              rm -f /var/se3/Docs/trombine/$uid.* 
 229  #               echo "rm -fr /home/$uid <br>" 
 230         fi
 231          
 232        else
 233          echo "/home/$uid n'existe pas <br>"
 234        fi
 235  
 236      # A VOIR pour LCS:
 237      # Faut-il un dump de sauvegarde?...
 238      #db_name=$(echo "$uid" | sed -e "s/-//g" | sed -e "s/_//g" | sed -e "s/\.//g")
 239      #echo "DROP DATABASE ${db_name}" | mysql -h $dbhost -u $dbuser -p$dbpass > /dev/null 2>&1
 240      #echo "delete from personne where login = '$uid'" | mysql -h $dbhost lcs_db -u $dbuser -p$dbpass
 241      done
 242  
 243  fi
 244  
 245  
 246  # if [ "$BACKUP" = "1" ]; then 
 247  # getmysql "5" $VERSBOSE /etc/se3/config_b.cache.sh
 248  # fi
 249  
 250  
 251  
 252  
 253  
 254  
 255  
 256  
 257  
 258  
 259  


Generated: Tue Mar 17 22:47:18 2015 Cross-referenced by PHPXref 0.7.1