#!/bin/bash
# This script will find the username of each httpdocs folder in the vhosts folder
# of a Plesk installation and set every file and folder inside that folder to be owned by that user
# It will also set files to 644 and folders to 755 permission. This is perfect for an installation using FastCGI/
VHOST_PATH="/var/www/vhosts"
echo "Performing operations on:"
cd "$VHOST_PATH"
for DIR in `ls -d -- */`
do
# Check if file exists before attempting to perform operations
if [ -f $CONFIG ]; then
if [ -d "$DIR/httpdocs" ]; then
USER=`stat -c "%U" $DIR/httpdocs`
echo "$DIR - Owner set to $USER"
find "$DIR/httpdocs" -type d -print0 | xargs -0 chmod 755
find "$DIR/httpdocs" -type f -print0 | xargs -0 chmod 644
chown -Rf $USER:psacln $DIR/httpdocs
chown $USER:psaserv $DIR/httpdocs
fi
fi
done