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

Hello,

put set -x on the second line, and run script again to see the problem.

still not working, this is what is doing:

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 '{}' ';'

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...

I think, find would be executed in its own shell (subshell) and you dont need to escape ";"at all.

try

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

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:

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:

 ./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

cron:
Should be

/usr/bin/chmod 777  /moneta_polled01/mediation_gsm/* 

You need \ it is part of find syntax...

1 Like

Just to confirm \ is NOT at all part of find syntax. proof below...

 
$> export fn="find . -xdev -size +10000000c -exec ls -ld {} \\;"
$> $fn
find: incomplete statement
$> find . -xdev -size +10000000c -exec ls -ld {} \;
-rw -r-----1 lscpvbf lscpuser 28789228 25 Mar 07:30 ./ CUST_TM_I017_2_000_20110325_004237.txt
$> export fn="find . -xdev -size +10000000c -exec ls -ld {} \;"
$> $fn
find: incomplete statement
$> export fn="find . -xdev -size +10000000c -exec ls -ld {} ;"
$> $fn
-rw -r-----1 lscpvbf lscpuser 28789228 25 Mar 07:30 ./ CUST_TM_I017_2_000_20110325_004237.txt
 
ant:/home/vbe $ find . -xdev -size +10000000c -exec ls -ld {} ;
find: -exec not terminated with ';'
ant:/home/vbe $ find . -xdev -size +10000000c -exec ls -ld {} \;  
-rw-rw-rw-   1 vbe        bin        78273744 Jan 20  2009 ./AdbeRdr709_hpux_enu.tar.gz
find: cannot open ./.test

Remember: We were not talking about variable substitution... If you are correct in absolute : the syntax requires ; the shell straight away will interpret therefore the use of \ , but here we were on command line... in a script, look the beginning...