Monday, February 11, 2013

Clone Permission


List all the files with ownership and full path :

find $PWD -type d  -ls

List all the directories with ownership and full path :

find $PWD -type f  -ls

List all the permissions with full path recursively :

find ${PWD} -exec stat -c' %a %n' {} \;

 ==================================================================
Script to Change Files

Usage : this script and file name
Script.sh filename

#! /bin/bash
i=0
t=`cat $1 | wc -l`
while [ $i -lt $t ]
        do
                i=$[$i + 1]
                read line
                user=`echo $line | awk '{print $5}'`
                group=`echo $line | awk '{print $6}'`
                file=`echo $line | awk '{print $NF}'`
                #echo $user
                #echo $group
                #echo $file
                chown $user:$group $file
                if [ $? -eq 0 ] ; then
                        echo File  $line is updated >> /tmp/updatedFiles.txt
                        else
                        echo File $line is failed >> /tmp/updatedFilesFailed.txt
                fi
        done < $1
#END

==================================================================

Script to ChangeDir

Usage : this script and file name
Script.sh filename

#! /bin/bash
i=0
t=`cat $1 | wc -l`
while [ $i -lt $t ]
        do
                i=$[$i + 1]
                read line
                user=`echo $line | awk '{print $5}'`
                group=`echo $line | awk '{print $6}'`
                file=`echo $line | awk '{print $NF}'`
#               echo $user
#               echo $group
#               echo $file
                chown $user:$group $file
                if [ $? -eq 0 ] ; then
                        echo Directory  $line is updated >> /tmp/updatedDirs.txt
                        else
                        echo Directory $line is failed >> /tmp/updatedDirsFailed.txt
                fi
        done < $1
#END

==================================================================

Changes permission for all the files :

Script to Change Files

Usage : this script and file name
Script.sh filename

#! /bin/bash
i=0
t=`cat $1 | wc -l`
while [ $i -lt $t ]
        do
                i=$[$i + 1]
                read line
                permission=`echo $line | awk '{print $1}'`
                file=`echo $line | awk '{print $NF}'`
                #echo $permission
                #echo $file
                chmod $permission $file
                if [ $? -eq 0 ] ; then
                        echo Permission  $line is updated >> /tmp/updatedPermission.txt
                        else
                        echo Permission $line is failed >> /tmp/updatedPermissionFailed.txt
                fi
        done < $1
#END


No comments: