[Samba] script to move user profile directories

Jeff Davis jdavis at standard.k12.ca.us
Wed Apr 16 16:21:51 GMT 2008

I've been trying to write a script to move user profile directories, and 
so far not so good.  Made the mistake of allowing windows to create the 
profile dir in the user's homedir, and am attempting to rectify after 
the fact.  really do not want to go from machine to machine to deal with 
this manually as it's monumentally inefficient.

Some symptoms are the inability to manage the profile on the workstation 
- in my computer->properties->advanced->user profiles, copy and delete 
are greyed out for the affected account, even for local admin.

I've tried to use the root postexec in smb.conf from the homes stanza to 
trigger the move when the user logs off.  Everything moves but seem to 
be having the above issues with the profiles once they move.

using smb-tools to update ldap with the correct profile path, but I'm 
wondering if something in the ntuser.dat or some other binary file needs 
to be changed as well.

"windows is so cool" (!%@%#&@&!~)

Depending on primary group membership the users profile is moved to the 
appropriate server

Here's the script.

# this script is called by samba's root postexec from the user's home 
# it checks to see if the user's profile is in the users home dir.  If 
so, it is
# moved to the samba/profiles directory, and ldap is updated to reflect 
the change
# if the user has no profile directory, one is created.
# JD 4/2/2008
if ( [ -z $1 ] || [ -z $2 ] ); then
        echo ""
        echo "* Moves user profiles from their home directory to the 
profile directory on"
        echo "* //staff or //teach, depending on group membership, and 
updates their LDAP"
        echo "* entry accordingly"
        echo ""
        echo "usage: profiles.sh <userid> <group>"
        echo ""

        if [ $2 = "staff" ]; then
        elif [ $2 = "teachers" ]; then
        elif [ $2 = "students" ]; then
        else exit

#       echo "$server is the server" >> 
        if [ ! -d /net/$server/home/samba/profiles/$1 ]; then
                if [ -d /net/$server/home/$1/profile ]
                        echo "$1 Needs to have their profile moved" >> 
                        smbldap-usermod -F "\\\\$server\\profiles\\$1" $1
                        mv /net/$server/home/$1/profile 
                        echo "$(date) Profile moved for $1" >> 
                        echo "$(date) $1 has no existing profile 
directory" >> /net/staff/home/samba/netlogon/scripts/profiles.txt
                        mkdir /net/$server/home/samba/profiles/$1
                        chown $1:$2 /net/$server/home/samba/profiles/$1
                        smbldap-usermod -F "\\\\$server\\profiles\\$1" $1
                        echo "$(date) Profile directory created for $1" 
 >> /net/staff/home/samba/netlogon/scripts/profiles.txt

More information about the samba mailing list