Chown & Chmod Cron task

7 posts / 0 new
Last post
#1 Wed, 09/07/2011 - 08:22
louminsk

Chown & Chmod Cron task

Hi

I wanna create a cron task for different joomla website under virtualmin i manually do this following command via ssh

cd /home/domainname1
sudo chown -R -v apache:apache public_html
sudo chown -v user1:group1 public_html
cd /home/domainname1/public_html
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;

and for a second domain for example

cd /home/domainname2
sudo chown -R -v apache:apache public_html
sudo chown -v user2:group2 public_html
cd /home/domainname2/public_html
find . -type f -exec chmod 644 {} \;
find . -type d -exec chmod 755 {} \;

i wanna run this weekly

I have no idea how to process , create a script or type this different command after create a new cron task in webmin

Thanks for your help

Wed, 09/07/2011 - 09:39
andreychek

Howdy,

I'd make the above into a script, and then call that script from cron.

-Eric

Wed, 09/07/2011 - 10:52
louminsk

Thank you Eric

I have no idea of the structur of the script need. I was reading a few php script on the net but the syntax is far of the ssh command line i use. Can i paste straight like this in a file chown.php ?

#!/bin/bash
cd /home/domainname1
sudo chown -R -v apache:apache public_html
sudo chown -v user1:group1 public_html

thanks

philippe

Wed, 09/07/2011 - 10:06
andreychek

Yup, that should work just fine! Though, it looks like you have a trailing slash behind the word "bash", you probably don't want that. But that should otherwise work just fine.

-Eric

Wed, 09/07/2011 - 11:54 (Reply to #4)
louminsk

Hello Eric I done my first test of my first script using the following code

#!/bin/bash -x
cd /home/walpy/
sudo chown -R -v apache:apache public_html
sudo chown -v walpy:walpy public_html

my script chown is root:root 755, path = /etc/chown

the output when running the script in Webmin manually i have this error in the output

  • cd /home/walpy/
  • sudo chown -R -v apache:apache public_html sudo: sorry, you must have a tty to run sudo
  • sudo chown -v walpy:walpy public_html sudo: sorry, you must have a tty to run sudo

When i launch this script /etc/chown from my pc in command line ,there is no issue and all the files are chown correctly Im logued as root in webmin.

http://img840.imageshack.us/img840/7572/crontask.th.png

Wed, 09/07/2011 - 12:03
andreychek

You may want to just always run that script as root, and not use "sudo" in the script. That would be a simple way to fix the problem you're seeing.

-Eric

Wed, 09/07/2011 - 12:23 (Reply to #6)
louminsk

Simple and works thanks a lot Eric Really Helpfull

The code finally used

#!/bin/bash -x
cd /home/domainname/
chown -R -v apache:apache public_html
chown -v user:group public_html
Topic locked