Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have multiple users on one machine with FreeBSD7.3. Each user has his own site (only one). Each site is a copy of master-site with slight differences (ie. database configuration, template files).
It's like many Wordpresses with different users on one machine.

The problem is:
I've made a patch for master-site. How i can update all of this sites at once, rightly changing user permissions and ownership.

IE: I have patch like it:

/temp/patch/www/
--index.php
--includes/system.php

And i have many users with the same directory structure and few other files:

/home/mike/www/mikebestsite.com/
--index.php
--index2.php
--includes/system.php

/home/john/www/superjohnsite.com/
--index.php
--includes/system.php
--includes/break.php

/home/larry/www/larry-e-king.com/
--index.php
--includes/system.php
--css/larry.css

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Here's a quick bash snippet that should do the trick for you.

I'm making an assumption that everything in /home that is a directory and matches *\.com is a site where you want to replace index.php and includes/system.php. If this logic is not suitable, you might have to make some modifications yourself.

I have tested it within limited constraints. Make sure that the ls -ld output in FreeBSD has the user in the third field and the group in the forth field. Also, --reply=yes is a GNUism. You might have to use -f or the BSD equivalent to force replacement of an existing file without interaction.

for D in `find /home -type d -name '*\.com'`
   do
     myuser=`ls -ld $D | awk '{print $3}'`
     mygroup=`ls -ld $D | awk '{print $4}'`

     echo "Updating ${D}..."
     cp ${D}/index.php ${D}/index.php.ORIG
     cp ${D}/includes/system.php ${D}/includes/system.php.ORIG
     cp --reply=yes /path/to/temp/patch/www/index.php ${D}
     cp --reply=yes /path/to/temp/patch/www/includes/system.php ${D}/includes
     chown $myuser:$mygroup ${D}/index.php
     chown $myuser:$mygroup ${D}/includes/system.php
     echo "--------------------------------"
     echo ""
done
share|improve this answer
    
Brilliant! Delightfully! Magnificently! –  kirillorloff Jul 28 '10 at 21:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.