Set CRON to CHMOD

Set CRON to CHMOD

Posted by: Audioslave
Posted on: 2007-06-24 22:56:00

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

What I've gathered is that
/bin/chmod 755 /home/username/*.php
would accomplish all the PHP files in that directory. If I set it to
/bin/chmod 755 /home/username/*/*.php
would it be recursive?

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

Re: Set CRON to CHMOD

Posted by: scjessey
Posted on: 2007-06-25 05:18:00

I'm no expert, but I think it would have to be:

/bin/chmod -R 755 /home/username/*.php

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

Re: Set CRON to CHMOD

Posted by: vicm3
Posted on: 2007-06-25 06:38:00

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

Re: Set CRON to CHMOD

Posted by: sdayman
Posted on: 2007-06-25 06:38:00

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

Re: Set CRON to CHMOD

Posted by: matttail
Posted on: 2007-06-25 08:42:00

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

Re: Set CRON to CHMOD

Posted by: Audioslave
Posted on: 2007-06-25 10:41:00

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?

Re: Set CRON to CHMOD

Posted by: scjessey
Posted on: 2007-06-25 10:53:00

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

Re: Set CRON to CHMOD

Posted by: Audioslave
Posted on: 2007-07-12 23:08:00

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

Tags: chmod 755croncluelessphp filesrecursivefoldersaccomplish