Help on script to change permissions


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help on script to change permissions
# 1  
Old 09-19-2012
Help on script to change permissions

Hi

I have written the following script that later I want to put in cron,:

Code:
#!/bin/bash
_find="/usr/bin/find"
_paths="/moneta_polled01/mediation_gsm /moneta_polled01/mediation_mmsc"
for d in $_paths
do
$_find $d -type f -exec chmod 777 {} \;
done

but it does not seem to be working for the second subdirectory define on line 3.

Please can you help
# 2  
Old 09-19-2012
Hello,

put set -x on the second line, and run script again to see the problem.
# 3  
Old 09-19-2012
Help on script to change permissions

still not working, this is what is doing:

Code:
root@moneta # ./perm
+ _find=/usr/bin/find
+ _paths='/moneta_polled01/mediation_gsm /moneta_polled01/mediation_mmsc'
+ for d in '$_paths'
+ /usr/bin/find /moneta_polled01/mediation_gsm -type f -exec chmod 777 '{}' ';'

# 4  
Old 09-19-2012
There is no reason it not executing unless and that you say nothing, you are not executing the script as root.. in which case it cannot change what doesnt belong to the UID running the script...
# 5  
Old 09-19-2012
I think, find would be executed in its own shell (subshell) and you dont need to escape ";"at all.

try

Code:
 $_find $d -type f -exec chmod 777 {} ;

# 6  
Old 09-19-2012
Hi

It looks like its working, what I think is happening, is because these directories are being feed with files all the time, it looks like is not working, but it is.
But I dont quite understand why a cron entry with chmod command doest not work:

Code:
0,5,10,15,20,25,30,35,40,45,50,55 * * * * /usr/bin/chmod 777 * /moneta_polled01/mediation_gsm

---------- Post updated at 03:10 PM ---------- Previous update was at 03:02 PM ----------

after removing "\" as suggested by vidyadhar85, I got the following:

Code:
 ./perm
+ _find=/usr/bin/find
+ _paths='/moneta_polled01/mediation_gsm /moneta_polled01/mediation_mmsc'
+ for d in '$_paths'
+ /usr/bin/find /moneta_polled01/mediation_gsm -type f -exec chmod 777 '{}'
/usr/bin/find: incomplete statement
+ for d in '$_paths'
+ /usr/bin/find /moneta_polled01/mediation_mmsc -type f -exec chmod 777 '{}'
/usr/bin/find: incomplete statement

# 7  
Old 09-19-2012
cron:
Should be
Code:
/usr/bin/chmod 777  /moneta_polled01/mediation_gsm/*

You need \ it is part of find syntax...
This User Gave Thanks to vbe For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to change Permissions on files and directories

Hey, It's me again. Have a problem, that's not really a problem. I have the below script, that goes to the directory I want it to go to. lists out the directories available, lets you choose the directory you want, then it changes the permissions on said directory. using chmod -R and chown -R. ... (2 Replies)
Discussion started by: gkelly1117
2 Replies

2. Shell Programming and Scripting

Help on script to change permissions

Hi All I have the following script that is supposed to change permissions of incoming files to a directory, but it does not seem to do what I want, please can you help: mkdir -p /tmp/tmpdir find /moneta_polled01/sgsn/ -exec ls -l {} \; |grep -v rwxrwxrwx |awk '{print $9}' >... (4 Replies)
Discussion started by: fretagi
4 Replies

3. UNIX for Dummies Questions & Answers

Change permissions

Hi everyboy, I've installed a Virtualbox on my computer, inside the VB i'm running RedHat. So my problems it's that i need to run the scripts runasroot.sh to install the guest addiont, i'm doing this by console. I wrote chmod 775 ./runasroot.sh but doesn't works. I'm login as root user. Any... (8 Replies)
Discussion started by: Newer
8 Replies

4. UNIX for Dummies Questions & Answers

To change permissions in mv or cp

Is there any option with mv or cp command so that a file permissions and name of the file can be changed in single mv or cp command. I searched man mv but doesn't found any option like that. (3 Replies)
Discussion started by: Devesh5683
3 Replies

5. Shell Programming and Scripting

ksh; Change file permissions, update file, change permissions back?

Hi, I am creating a ksh script to search for a string of text inside files within a directory tree. Some of these file are going to be read/execute only. I know to use chmod to change the permissions of the file, but I want to preserve the original permissions after writing to the file. How can I... (3 Replies)
Discussion started by: right_coaster
3 Replies

6. Windows & DOS: Issues & Discussions

script to change widows update permissions

I want to allow windows update when ordinary users are logged on, I'm pretty sure that adjusting the permissions registry entry HEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/WindowsUpdate to allow acces to all domins users does the trick. I already have a logon.bat that runs at... (0 Replies)
Discussion started by: barrydocks
0 Replies

7. UNIX for Advanced & Expert Users

script to recursively change permissions on file and dirs differently?

Hi there, I need to change all files/dirs 1. all files with 744 2. all dirs with 755 is there a script for that ? thanks, thegunman (13 Replies)
Discussion started by: TheGunMan
13 Replies

8. UNIX for Dummies Questions & Answers

Need to change permissions

Hi everyone, There are couple of users of which i need to give 2 of the users admin rights so that they are able to run the administration commands like "zoneadm" and locale. When logged in as root i am obviously able to do that.please suggest any way by which the other 2 user's permissions can... (3 Replies)
Discussion started by: sankasu
3 Replies

9. Shell Programming and Scripting

script to change the access permissions of the files

Hi, I want to change the access permissions of the files whose extension is same.For example *.c but these are inside a directory and inside that other directory is there and it contains the .c files..for example-- So my aim is to search the files under src and change the access permissions... (3 Replies)
Discussion started by: smartgupta
3 Replies

10. Linux

Korn Shell Script to change the permissions

Hi, All I am trying to change the permission for all the files in the current dir such that the user(owner) have the read write and excute permissions. When I excute the korn shell it will change the whole files and directory permissions as "rwx". Any help will be highly appreciated. Thanks (1 Reply)
Discussion started by: uhelp
1 Replies
Login or Register to Ask a Question