Le script permet d’afficher (ou de stocker dans un fichier) les droits attribués pour chaque dossier d’une arborescence (groupes uniquement).
#!/bin/sh# extraitDroitDossier.sh# @author : Eric Quinton# @date : 2011-04-28# modification : 6/4/12#script permettant d'extraire la liste des droits attribues a un dossier et aux sous-dossiers# fournit une liste avec une entree par dossier, chaque groupe etant separe par un espace# Recuperation des parametres d'entreePROFONDEUR=1while getopts "p:c:d:-:h" OPTdo # Gestion des options longues if test $OPT = '-' ; then LONGOPT="${OPTARG%%=*}" OPTARG="${OPTARG#*=}" case $LONGOPT in chemin) OPT="c";; destination) OPT="d";; profondeur) OPT="p";; help) OPT="h";; *) echo "option longue non permise -- $LONGOPT" >&2 ;exit65 ;; esac fi case $OPT in c) CHEMIN=$OPTARG;; d) DEST=$OPTARG;; p) PROFONDEUR=$OPTARG;; h) echo "Utilisation : extraitDroitsDossier.sh [arguments]" echo "[--chemin=chemin|-c chemin] : chemin de base a interroger" echo "[--profondeur=nombre|-p nombre] : nombre de sous-dossiers a traiter" echo "[--destination=destination|-d destination] : destination du resultat (pour l'ecran : ne pas renseigner)" exit 0 ;; *) echo "option inconnue. creaationDossier.sh -h pour plus d'informations" exit 65 ;; esacdone# Verification que le chemin est renseigneif test -z $CHEMIN ; then echo "Le dossier a interroger n'est pas renseigne" exit 65fi# Verification de l'existence d'un fichier de destinationif test ! -z $DEST ;then if test -f $DEST then echo -n "Le fichier $DEST existe. L'ecraser (o,n)" read REPONSE if (test "$REPONSE" = "o") then rm $DEST else exit 1 fi fifi# Lancement de l'extractionfind $CHEMIN -maxdepth $PROFONDEUR -type d|while read DOSSIERdo RESULT=`getfacl "$DOSSIER" 2>/dev/null|grep -v ^.*---|grep -v ^#\ owner|grep -v ^default| grep -v ^#\ group|grep -v ^user|grep -v ^mask|grep -v ^group:: |sed s/^..file..//` if test "$RESULT" then if test "$DEST" then echo /$RESULT >> $DEST else echo /$RESULT fi fidone