Find the answer to your Linux question:
Results 1 to 5 of 5
Hi all, i am trying to write a script that will check the ACL's on the directories and files and puts the output into a text file. Can someone please ...
  1. #1
    Just Joined! new_linux_user's Avatar
    Join Date
    Jan 2006
    Posts
    16

    File Permission check script

    Hi all, i am trying to write a script that will check the ACL's on the directories and files and puts the output into a text file. Can someone please direct me to the right place. I have written some scripts but don't know where to begin.

    Thanks in advance.

  2. #2
    Linux Enthusiast likwid's Avatar
    Join Date
    Dec 2006
    Location
    MA
    Posts
    649
    getfacl outputs ACL's, so you would want something like


    Code:
    find / -exec getfacl {} \; >> /tmp/acl.txt
    That shows the ACL of everything under / and outputs it to /tmp/acl.txt. You could make the starting path and outputfile command line options. Something like this would do:

    Code:
    #!/bin/bash
    
    if [ $# -lt 2 ]; then
       printf "Usage: `basename $0` path_to_search output_file\n"
       exit 1;
    fi
    
    if [ -f $2 ]; then
       printf "$2 already exists, please choose an output file that does not exist.\
       exit 1;
    fi
    
    (find $1 -exec getfacl {} \;) | tee $2
    This basically just takes a search path and an outputfile, and executes getfacl on each entry under the search path, outputting the contents to both the terminal and the outputfile. The reason I did this is because find seemingly always returns a 1, so I couldn't put something at the end that said "Your ACL's are in $2" based on an if statement on the exit status, and "Find failed for some reason" based on a non zero exit status.

  3. #3
    Just Joined! new_linux_user's Avatar
    Join Date
    Jan 2006
    Posts
    16

    Thanks

    Thank you so much for your help..

  4. #4
    Just Joined!
    Join Date
    May 2008
    Posts
    10
    How could I use the output from the getfacl script to create facls on another system.

  5. #5
    Just Joined!
    Join Date
    Oct 2008
    Posts
    1

    Great command...but one more step.

    This is a great one liner, but I have an addition I'd like some help with. This one liner dumps things like this to the file:

    # file: home/savagephp
    # owner: savagephp
    # group: users
    user::rwx
    group::--x
    other::--x

    I'd like to be able to grep against this output and then only output those entries that match my criteria. For example, if I want to only dump to the /tmp/acl.txt file those entries that have a group permission setting of 'r-x', how could this be done? grep by itself won't work because it only returns the line that matched and not the rest of the getfacl output for that file.

    Thanks.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...