Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I'm trying to write a script which takes 3 arguments as input.

  1. path : where the files we want to check the ownership of are found.

  2. expected ownership : the expected ownership given as argument 2

  3. group : argument 3

There will be a whitelist file as well, which will have some of the file names. If any of the whitelisted file names are found, they should be skipped.

The script needs to print a message if any of the file's ownership doesn't match otherwise, it should print "all files have the expected ownership".

I tired the script but it's not working.. am not sure how to work with whitelist file logic.

Can someone please help me out.

#!/usr/bin/env bash
PATH=$1
Owner=$2
Group=$3
WHITELIST="(/tmp/file_whitelist.txt)"

listcount=0
whitelist_matches=0

while IFS="" read -r matchedentry; do
    if [[ "$matchedentry" =~ $WHITELIST ]]; then
        ((whitelist_matches++))
    else
        echo -e "$matchedentry\r"
        ((listcount++))
    fi
done < <(find "$PATH" -perm /u+w -user $Owner -o -perm /g+w -group $GROUP)

if (( $listcount > 0 )); then
        echo "$listcount items are having by '$Owner' ($whitelist_matches whitelisted)."
else
        echo "Files which are Not having correct ownership found ($whitelist_matches whitelisted)."
fi
share|improve this question
add comment

1 Answer

As soon as you do this:

PATH=$1

your script will no longer be able to locate the find program. Don't use $UPPER_CASE_VARS

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.