Set CRON to CHMOD


#1

I’m looking to set a CRON to CHMOD all of my folders 755 and files 771.

What I’ve gathered is that
[color=#CC0000]/bin/chmod 755 /home/username/.php[/color]
would accomplish all the PHP files in that directory. If I set it to
[color=#CC0000]/bin/chmod 755 /home/username/
/*.php[/color]
would it be recursive?

Also, I am COMPLETELY clueless on how to CHMOD directories recursively as such.


#2

I’m no expert, but I think it would have to be:/bin/chmod -R 755 /home/username/*.phpYou’d best get a confirmation from someone who knows UNIX commands though, because I’m a novice. Also, I would’ve thought it would be better to specify your domain as well, or you’ll end up setting all your logs and mail to 755 too.


si-blog | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


#3

Well the -R switch is right is recursive… but I prefer doing other way.

find ./ -type d -exec chmod 751 {} ;

From where I am all my directories chmod to 751 (you can change ./ to any path where you are the owner)

find ./ -iname “*.php” -exec chmod 755{} ;

From where I am all my files ending with .php chmod to 755.
You can tweak to your home and maybe you don’t want to change the logs and mail directories… anyway find let you do lots of things.

Regards


use VICM3 for a full 97USD discount on your first year!


#4

It wouldn’t be completely recursive. When I need to do something recursively, I’d try something like:
find ./ -print | grep .php | xargs chmod 755

This will find files that contain .php (though with the dot, it may find plain “php” too) then xargs will send the results to chmod.

-Scott


#5

Just a note, hopefully for your benefit. vicm3’s suggested solution would be a script, to use that you’d need to save that as a file (script_name.sh) on your server and then have cron call that script. The solution is great, just want to save you from some possible confusion.

–Matttail
art.googlies.net - personal website


#6

The problem I am coming across now is that the files have spaces in their names, so how find is sending the files to CHMOD it splits them up when there’s a space, leading to the wrong paths. I can’t take spaces out of the names (It’s a key issue that I have no control over), so is there any chance of this working?


#7

I believe it is possible to work with filenames that may have spaces by putting the filename in double quotes.


si-blog | Keystone Websites
Save $97 on yearly plans with promo code [color=#CC0000]SCJESSEY97[/color]


#8

But in the context of those scripts, how would I keep the file names together in quotes?