I am trying to write a script which would retrieve the permissions of a group of files and directories. Then check each permission to see if they are set correctly. If the permissions are not set correctly then I would like it to echo which directory or group of files permissions were incorrectly set.So far what I have is, I have used 'find' to recursively find all files and directories inside a certain directory and then execute stat to return the current permissions. From the returned list of permissions I then use an if-then statement to check if any files or directories have different permissions then what are expected. This is accomplished by the != operator and using pattern matching. So all files should have permissions set to 444 and directories to 555 and if not return that the permissions are wrong.for site in $(echo /var/www/*)do    permcheckfile=$(find $site -type f -exec stat -c '%a' '{}' +)    permcheckdir=$(find $site -type d -exec stat -c '%a' '{}' +)    if [[ $permcheckfile != *444 ]]    then        echo $site file permissions are wrong    else        echo $site file permissions are correct    fi    if [[ $permcheckdir != *555 ]]    then         echo $site directory permissions are wrong    else        echo $site directory permissions are correct    fi doneThe problem found with the script above is sometimes it will return false positives and I have no idea why.Does anyone have an idea where I am going wrong? Is there a better way of accomplishing what I am trying to achieve? Any help or suggestions would be greatly appreciated. Thank you for your time and help
Bash script to recursively obtain file and directory permissions, compare them to desired permissions and return if correct or not
bash;shell script;shell;wildcards
You need to loop the permcheckfile and permcheckdir arrays.for site in $(echo /var/www/*)do     for file in $(find $site -type f -exec stat -c '%a' '{}' +)    do        if [[ $file != *444 ]]        then            echo $site/$file permissions are wrong        else            echo $site/$file permissions are correct        fi    done    for dir in $(find $site -type d -exec stat -c '%a' '{}' +)    do        if [[ $dir != *555 ]]        then            echo $site directory permissions are wrong        else            echo $site directory permissions are correct        fi    done done