Created
July 11, 2014 10:45
-
-
Save cypres/bf14792366389944c16a to your computer and use it in GitHub Desktop.
Fix permissions script
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
PATH=/var/www | |
USER=ftp | |
GROUP=www | |
# do an early exit if another find command is already running | |
/bin/ps axc | /usr/bin/awk '{ print $5 }' | /usr/bin/grep -q find | |
if [ $? -eq 0 ]; then | |
exit; | |
fi; | |
if [ ! -z "$1" ]; then | |
PATH=$1; | |
fi; | |
if [ ! -z "$2" ]; then | |
USER=$2; | |
fi; | |
if [ ! -z "$3" ]; then | |
GROUP=$3; | |
fi; | |
export IFS= | |
/usr/bin/nice -n 19 \ | |
/usr/bin/find $PATH \ | |
\( -type f ! -perm 660 -print0 -exec /bin/sh -c "/bin/chmod -f 660 \$1 && exit 2" name {} \; \) -or \ | |
\( -type d ! -perm 770 -print0 -exec /bin/sh -c "/bin/chmod -f 770 \$1 && exit 2" name {} \; \) -or \ | |
\( \( ! -user $USER -or ! -group $GROUP \) -exec /usr/sbin/chown -h -f $USER:$GROUP {} + \) > /dev/null |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment