0

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

1 Answer 1

4

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .