changing permission using scripts


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers changing permission using scripts
# 1  
Old 04-17-2004
changing permission using scripts

I have been trying to create a script that changes the user rights to read in the 'other' group across directories. The problem I'm having is that when i execute the script, the permissions of the directories remains the same.

HELP
# 2  
Old 04-17-2004
Lets see what you have done, please post your script, or at least the portion where you try and change directory permissions. In the mean time see man chmod
# 3  
Old 04-17-2004
Got it sorted

Thanks for replying, I found out what I was doing incorrectly so I managed to get it sorted.
Cheers
# 4  
Old 04-17-2004
please post your solution in hopes that others with a similar problem can see your solution. also please describe what you were trying to do.
# 5  
Old 04-21-2004
After creating the directories shown below, I wanted to create a script that would show the permission for these directories using the ls -ld command...

mkdir SPADE
cd SPADE
mkdir HARLEM BRONX HACKNEY WHITEHALL BARKING
cd HARLEM
mkdir CANADA SHOELY PALUVA DELOPS

So I created this little script....

echo "This script demonstrates the permission for the directories"
echo""
echo "Permission for the SPADE directory"
cd SPADE
ls -ld
echo ""
echo "Permission for the HARLEM directory"
cd HARLEM
ls -ld
echo ""
echo "Permission for the BRONX directory"
cd ..
cd BRONX
ls -ld
echo ""
echo "Permission for the HACKNEY directory"
cd ..
cd HACKNEY
ls -ld
echo ""
echo "Permission for the WHITEHALL directory"
cd ..
cd WHITEHALL
ls -ld
echo ""
echo "Permission for the BARKING directory"
cd ..
cd BARKING
ls -ld
cd ..
cd HARLEM
echo ""
echo "Permission for the CANADA directory"
cd CANADA
ls -ld
echo""
echo "Permission for the SHOELY directory"
cd ..
cd SHOELY
ls -ld
echo ""
echo "Permission for the PALUVA directory"
cd ..
cd PALUVA
ls -ld
echo""
echo "Permission for the DELOPS directory"
cd ..
cd DELOPS
ls -ld

Can this script be shortened to create the same results??
# 6  
Old 04-21-2004
yes, you could use a for loop and store each directory name in one single array. disregarding specific shell syntax, and the fact that i dont know offhand what shell can actually use arrays (if not you could store each name in a file and have the for (or foreach) loop run through the file), here is an out line of how that would work:

Code:
directories_a[4] = {HARLEM, BRONX, HACKNEY, WHITEHALL, BARKING};

directories_b[3] = {CANADA, SHOELY, PALUVA, DELOPS};

mkdir SPADE;
cd SPADE;

for(i = 0; i<=4; i++)
{
    mkdir $directories_a[i];
    var_permissions_a[i]+=`ls -d directories_a[i]`;
}

cd HARLEM;

for (y = 0; y<=3; y++)
{
    mkdir $directories_b[y];
    var_permissions_b[y]+=`ls -d directories_b[y]`;
}

then output whats stored in var_permissions_a and var_permissions_b.

now, please keep in mind that the code i just wrote above is just ment as a prototype, you will have to make it wokr with whatever language your script is in. that stuff up there becomes a mix of at least two different languages and wont run like that on anything




Smilie
# 7  
Old 04-21-2004
yes! For starters, you can use the -p switch on the mkdir command. mkdir -p This will create all child directories under a parent if they do not already exist. Secondly, you can set the umask for the user that runs the script so that the directories are created with the desired level of permissions. Lastly, use the find command to search the directories for a given permissions level, or for any file that has permissions less than what you desire. Output these files, or change the permissions of these files with the find command.

See the following man pages for syntax:
man chmod
man mkdir
man find

Last edited by google; 04-21-2004 at 11:16 PM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

set only some command & scripts permission to a particular user

hi, i am new in unix.......i am using bash and i want to create a user which has only some command and scripts permission.........is it possible? thanx (1 Reply)
Discussion started by: rakeshtomar82
1 Replies

2. UNIX for Dummies Questions & Answers

Permission denied when changing root password after reset

I have a Solaris 10 machine that I didn't know the root password to so I went into single user mode and removed the password from the shadow file and rebooted and I am able to login with no password now. But my problem is that when I try to change the root password from no password to something... (0 Replies)
Discussion started by: darkone_d1_2000
0 Replies

3. Shell Programming and Scripting

Changing file permission upon creation in a directory

I want to change the permission of a file when it gets created in a particular directory. For instance, I have directory MyDir. Everytime a file gets created in that directory, I would like to change the permission to 777. The context is that I have a 3rd party appication running as root. Only... (2 Replies)
Discussion started by: laiko
2 Replies

4. Shell Programming and Scripting

Changing file permission recursively

I have a directory named DIR. The contents of the directory is something like: a.sh b.sh cghsk.sh assjsjkd gdshddll DFG/ ... ... Where only DFG/ is a folder. I want to grant execute permission to all(a+x), for all the files directly under the DIR directory except the files that... (4 Replies)
Discussion started by: proactiveaditya
4 Replies

5. Shell Programming and Scripting

how to exclude file when changing permission

I have files as below: erf100.sh erf101.sh erf102.sh erf103.sh erf104.sh erf105.sh I can easily change permission of all files to 755 by issuing command below: chmod 755 erf*.sh; how do i change permission of all files but excluding file erf102.sh? thanks best regards (2 Replies)
Discussion started by: khchong
2 Replies

6. Shell Programming and Scripting

Changing the Bash Scripts to Bourne Scripts:URGENT

Hi, I have to write a program to compute the checksums of files ./script.sh I wrote the program using bash and it took me forever since I am a beginner but it works very well. I'm getting so close to the deadline and I realised today that actually I have to use normal Bourne shell... (3 Replies)
Discussion started by: pgarg1989
3 Replies

7. UNIX for Dummies Questions & Answers

changing scripts in /etc/rc2.d

This is a newbie question in which I feel almost ashamed in asking lol. I am told to make changes to /etc/rc2.d so that only certain scripts run. If I change something like S05netconfig to s05netconfig will it still run? What is the difference between S and s scripts (I see both types in there).... (1 Reply)
Discussion started by: rkruck
1 Replies

8. UNIX for Dummies Questions & Answers

Scripts and changing users

Hi, I am writing somescripts to shut down some services in Korn Shell. Some of the services are under different owners. For example when I want to shutdown NXserver I need to be "root", but when I shut down the webserver I need to be under a different user. Manual I would use "su root" and... (1 Reply)
Discussion started by: bonekrusher
1 Replies

9. Shell Programming and Scripting

changing permission using FTP

Dear all, i want to change file permision of remote dir using FTP. is that possible? what i'm doing is i'm simply doing chmod 777 filename after establishing the connection with remote server using ftp... but the result showing is 550 SITE CHMOD command failed. can any body plz help?... (3 Replies)
Discussion started by: panknil
3 Replies

10. Red Hat

changing wtmp ownership and permission

Hi, I am using redhat AS 3. Recently, I was asked to implement a security control on the OS: to change ownership of /var/log/wtmp to root:sys and permission to 600. However, when I made the change and reboot the machine, everything was reverted. How come? Please help. The following is the... (1 Reply)
Discussion started by: voa2mp3
1 Replies
Login or Register to Ask a Question