多个目录用更改用户权限进行更新

我在FreeBSD7.3的一台机器上有多个用户。 每个用户都有自己的网站(只有一个)。 每个站点都是主站点的副本(略有不同)(即数据库configuration,模板文件)。
就像许多用户在一台机器上的Wordpress一样。

问题是:
我为主站做了一个补丁。 我如何一次更新所有这些网站,正确地更改用户权限和所有权。

IE:我有这样的补丁:

/温度/贴片/ WWW /
–index.php
–includes / system.php

我有很多用户使用相同的目录结构和其他几个文件:

/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

这里有一个快速的bash片段,应该为你做的伎俩。

我假设/home中的所有内容都是一个目录,并匹配*\.com是一个你想要replaceindex.phpincludes/system.php的站点。 如果这个逻辑不适合,你可能需要自己做一些修改。

我已经在有限的条件下进行了testing。 确保FreeBSD的ls -ld输出在第三个字段中有用户,在第四个字段中有组。 另外,– --reply=yes是GNUism。 您可能必须使用-f或BSD等价物来强制replace现有文件而不进行交互。

 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