/script/fixweb : reset home permissions

Hello,

#!/bin/bash
HOMED="/home"
DIRS=$(ls -l $HOMED | grep ^d | awk '{ print $9}')
for d in $DIRS
do
        chown -R $d.$d $HOMED/$d
        echo "chown -R $d.$d $HOMED/$d"
done

The code above reset permissions in /home , chown:chgrp each folder to its owner. But it is not complete and cause some incompatiblities in email - ftp accounts.

Anyone can help me make this script complete ? It is very useful for virtualmin.

Thanks

Status: 
Active

Comments

Mostafa's picture
Submitted by Mostafa on Fri, 12/03/2010 - 05:12

This works better :

#!/bin/bash
HOMED="/home"
DIRS=$(ls -l $HOMED | grep ^d | awk '{ print $9}')
for d in $DIRS
do
        chown -R $d:$d $HOMED/$d
        echo "chown -R $d:$d $HOMED/$d"
        HOMES="/home/$d/homes"
        if [ "$(ls -A $HOMES)" ]; then
            ACCOUNTS=$(ls -l $HOMES | grep ^d | awk '{ print $9}')
            chown -R $ACCOUNTS.$d:$d $HOMES/$ACCOUNTS
            echo "chown -R $ACCOUNTS.$d:$d $HOMES/$ACCOUNTS"
        fi
done
Mostafa's picture
Submitted by Mostafa on Fri, 12/03/2010 - 05:17

I think this is almost complete :

#!/bin/bash
HOMED="/home"
DIRS=$(ls -l $HOMED | grep ^d | awk '{ print $9}')
for d in $DIRS
do
    if [ $d == "ftp" ]; then
        chown -R ftp:nogroup $HOMED/$d
    else
        chown -R $d:$d $HOMED/$d
        echo "chown -R $d:$d $HOMED/$d"
        HOMES="/home/$d/homes"
        if [ "$(ls -A $HOMES)" ]; then
            ACCOUNTS=$(ls -l $HOMES | grep ^d | awk '{ print $9}')
            chown -R $ACCOUNTS.$d:$d $HOMES/$ACCOUNTS
            echo "chown -R $ACCOUNTS.$d:$d $HOMES/$ACCOUNTS"
        fi
    fi
done

Any suggestions ?