I'm trying to write a script which takes 3 arguments as input.
path : where the files we want to check the ownership of are found.
expected ownership : the expected ownership given as argument 2
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