Languages and Scripting

Help on script to change permissions

 
SOLVED
Go to solution
NDO
Super Advisor

Help on script to change permissions

Hi

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

 

#!/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

6 REPLIES 6
Laurent Menase
Honored Contributor

Re: Help on script to change permissions

what is the error?

are you sure you have write access on dir and are owner of the files in /moneta_polled01/mediation_mmsc

else you could write

 

#!/bin/bash
_find="/usr/bin/find"
_paths="/moneta_polled01/mediation_gsm /moneta_polled01/mediation_mmsc"
$_find $_paths -type f -exec chmod 777 {} \;
OR

$_find $_paths -type f |xargs chmod 777
NDO
Super Advisor

Re: Help on script to change permissions

I am running as root.

Patrick Wallek
Honored Contributor
Solution

Re: Help on script to change permissions

The syntax appears correct.  I ran the script using POSIX shell on HP-UX and it parsed both directories I specififed.

 

Have you tried running the script with debug turned on via "/bin/bash -x" on the first line?

 

 

NDO
Super Advisor

Re: Help on script to change permissions

 

Hi,

 

I think the script is running fine, the problem is, there are files arriving every minute or so on those directories, so sometimes the script finishes to run, but some files did not get the permission changed because files are arriving all the time.

 

 

Patrick Wallek
Honored Contributor

Re: Help on script to change permissions

That would make perfect sense.

Dennis Handly
Acclaimed Contributor

Re: Help on script to change permissions

You can speed this up by changing the find to:

$_find $d -type f -exec chmod 777 {} +