Hello ,
I am trying to write a unix shell script to compare folder permission to say drwxr-x-wx and then send an email to my id in case the folders don't have the drwxr-x-wx permissions set for them .
I have been trying to come up with a script for few days now , pls help me:(
orig="drwxr-x-wx"
folder=/PATH/folder_name
check=$(ls -ld $folder | awk '{print $1}')
if [[ "$check" != "$orig" ]]; then
echo $folder |mailx -s "folder permission is changed" your@mailbox.com
fi
If you want to find any directory under a give dir that dosn't have your required permissions something like this should work.
PERM=753
PARENT=/PATH/to/parent
folders=$(find $PARENT -type d ! -perm $PERM)
if [ -n "$folders" ]
then
echo "$folders" | mailx -s "folder permissions have changed" your@mailbox.com
fi