Batch file 用于更改Plesk vhosts中文件夹所有权的脚本
我正在寻找一些帮助,在Linux中创建一个shell脚本,以便在所有者:组为apache:apache的Plesk环境中对某些文件夹执行批所有权更改 我想将所有者:组更改为:psacln 通过查看httpdocs文件夹的所有者可以确定FTP用户。 ^这是我遇到麻烦的部分 如果我将所有所有者设置为相同,我可以做一行:Batch file 用于更改Plesk vhosts中文件夹所有权的脚本,batch-file,permissions,ownership,Batch File,Permissions,Ownership,我正在寻找一些帮助,在Linux中创建一个shell脚本,以便在所有者:组为apache:apache的Plesk环境中对某些文件夹执行批所有权更改 我想将所有者:组更改为:psacln 通过查看httpdocs文件夹的所有者可以确定FTP用户。 ^这是我遇到麻烦的部分 如果我将所有所有者设置为相同,我可以做一行: find /var/www/vhosts/*/httpdocs -user apache -group apache -exec chown user:psacln {} \; 有
find /var/www/vhosts/*/httpdocs -user apache -group apache -exec chown user:psacln {} \;
有人可以帮助用户插入此命令吗
谢谢把它弄明白了。。。对于那些将来可能想使用它的人:
for dir in /var/www/vhosts/*
do
dir=${dir%*/}
permissions=`stat -c '%U' ${dir##*/}/httpdocs`
find ${dir##*/}/httpdocs -user apache -group apache -exec chown $permissions {} \;
done
由于
stat
在al-unices上的工作方式不同,我想我会分享我的脚本,将所有网站的所有权设置为Plesk中的正确所有者(在Plesk 11、11.5、12和12.5上测试):
\\\
代码说明:
cd
httpdocs
文件夹,则cd
返回vhosts文件夹,以便继续循环\\\好极了。我不得不稍微调整一下以适应稍有不同的场景,但这在几个服务器上保存了我的bacon,每个服务器上都有大量的站点,其中许多都是从其他服务器迁移过来的,具有稍微随机的权限!
cd /var/www/vhosts/
for f in *; do
if [[ -d "$f" && ! -L "$f" ]]; then
# Get necessary variables
FOLDERROOT="/var/www/vhosts/"
FOLDERPATH="/var/www/vhosts/$f/"
FTPUSER="$(ls -ld /var/www/vhosts/$f/ | awk '{print $3}')"
# Set correct rights for current website, if website has hosting!
cd $FOLDERPATH
if [ -d "$FOLDERPATH/httpdocs" ]; then
chown -R $FTPUSER:psacln httpdocs
chmod -R g+w httpdocs
find httpdocs -type d -exec chmod g+s {} \;
# Print success message
echo "Done... $FTPUSER is now correct owner of $FOLDERPATH."
fi
# Make sure we are back at the root, so we can continue looping
cd $FOLDERROOT
fi
done