Recursive ACL script

From SciNet Users Documentation
Revision as of 18:50, 15 October 2018 by Rzon (talk | contribs) (→‎Courtesy of Agata Disks)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Recursive ACL script

You may use/adapt one of the following bash scripts to recursively add or remove ACL attributes using gpfs built-in commands

Courtesy of Gabriel Devenyi

#!/bin/bash
# USAGE
#     - on one directory:     ./set_acl.sh aclfile dir_name
#     - on more directories:  ./set_acl.sh aclfile dir1_name dir2_name ...
#
# Based on a contributed script by Gabriel Devenyi.
#

set -euo pipefail
 
aclfile="$1"
shift

for dir in "$@"
do
    find "${dir}" -type d -exec mmputacl -i "${aclfile}" {} \; -exec mmputacl -d -i "${aclfile}" {} \; 
    find "${dir}" -type f -exec mmputacl -i "${aclfile}" {} \; 
done

Courtesy of Agata Disks

(http://csngwinfo.in2p3.fr/mediawiki/index.php/GPFS_ACL)

This script is a bit more verbose and precise in its error messages

#!/bin/bash
# USAGE
#     - on one directory:     ./set_acl.sh dir_name
#     - on more directories:  ./set_acl.sh 'dir_nam*'
#

# Path of the file that contains the ACL
ACL_FILE_PATH=/agatadisks/data/acl_file.acl

# Directories onto the ACLs have to be set
dirs=$1

# Recursive function that sets ACL to files and directories
set_acl () {
  curr_dir=$1
  for args in $curr_dir/*
  do
    if [ -f $args ]; then
      echo "ACL set on file $args"
      mmputacl -i $ACL_FILE_PATH $args
      if [ $? -ne 0 ]; then
        echo "ERROR: ACL not set on $args"
        exit -1
      fi
    fi
    if [ -d $args ]; then
      # Set Default ACL in directory
      mmputacl -i $ACL_FILE_PATH $args -d
      if [ $? -ne 0 ]; then
        echo "ERROR: Default ACL not set on $args"
        exit -1
      fi
      echo "Default ACL set on directory $args"
      # Set ACL in directory
      mmputacl -i $ACL_FILE_PATH $args
      if [ $? -ne 0 ]; then
        echo "ERROR: ACL not set on $args"
        exit -1
      fi
      echo "ACL set on directory $args"
      set_acl $args
    fi
  done
}
for dir in $dirs
do
  if [ ! -d $dir ]; then
    echo "ERROR: $dir is not a directory"
    exit -1
  fi
  set_acl $dir
done
exit 0

BACK TO Data Management