It is currently Sun May 20, 2018 7:41 am

Fixer Debugging

All times are UTC - 6 hours

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Wed Oct 27, 2010 12:16 pm   

Joined: Wed Oct 27, 2010 12:06 pm
Posts: 1
hi all, would you please help me debugging this script: which accepts a list of users as argument resiting those files permissions:
say our directory structure:
1- If a user or more are given as arguments, the script should reset files permissions as follows:
a. Directory ~/share to 750 (if it exists).
b. All regular files inside ~/share to 744.
c. All directories inside ~/share to 750.
d. All other regular files in ~ to 600 and all other directories in ~ to 700.
e. files of other types are left as they are.


$ user1 user2 user3

for user in $1 $2 $3 ; do
if -d /home/$1/share ; then
chmod 750 /home/$1/share ; else
echo “No folder named “share” is in $user home directory”

find /home/$1/share -type f -exec chmod 744 {} \;
find /home/$1/share -type d -exec chmod 750 {} \;
find ~ -type f -not \( -name share -o -name ~ \) -exec chmod 600
find ~ -type d -not \( -name share -o -name ~ \) -exec chmod 700

#2- If no arguments are give, the script should identify normal users in the system (UID >= 500) and for each user, reset files permissions as described above.
for User in $(cat /etc/passwd) ; do
UserId=$(echo $User | cut -d ":" -f 3)
if ($UserId -gt 500) ; then
# All reset permission stuff here

#3-At end of execution, produce a file named report.txt that contains a list of all files in the user's home directory including full path, owner, group and permissions for each file.
find . -ls | awk '{print $11 "\t" $5 "\t" $6 "\t" $1}' | tee report.txt
#it shoul be for all users
#where it should be saved?

chmod 755 fix-permissions
#for T.Issa, my id is 20347
exit 0

 PostPosted: Thu Oct 28, 2010 4:25 am   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
I kind of do not know what is a part of the script and what not. You should use the Code tags to show the script (e.g. the $ line is not in your script I hope.)
Instead of
for user in $1 $2 $3
, you should use
for user in "[email protected]"
, which is equivalen to
for user
Inside the loop, do not use $1, use $user. You do not have to shift if you do not use $1, $2 etc.
If you want to run the second part only if there was no argument, you should make it clear to the shell as well, so add something like
if (( ! $# )) ; then ... fi

You are probably running this script as root (otherwise, you would not be able to set other users' permissions), so a good place to store the resulting file is your home (usually /root).

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours

Who is online

Users browsing this forum: Google [Bot] and 8 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  

BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group