Script to Copy Home folders

Discussion in 'Mac Programming' started by applesaregood, Dec 6, 2007.

  1. applesaregood macrumors newbie

    Joined:
    Dec 6, 2007
    #1
    Hello,

    I have a server running 10.5. I have a hard drive of old Home folders for about 500 users that is from an older 10.3 server.

    Users want access to their old files. Just copying over the Home folders works fine. The issue I'm having is I don't want the Library folder to be copied over, because it contains old preferences that are causing a problem.

    So basically I have two folders that look like this:

    /Users
    jdoe
    dsmith
    bjones

    /oldUsers
    jdoe
    dsmith
    bjones

    Within each Home folder for each user I have a Documents, Movies, Pictures, Desktop, and Library folder. I need to copy the contents of /oldUsers/jdoe to /Users/jdoe, but not the Library folder.

    So I think I need a bash or AppleScript to do this. Programming really isn't my strong point and I'm just struggling reading sites on bash scripts.

    Thanks all
     
  2. casperghst42 macrumors member

    Joined:
    Jan 11, 2006
    #2
    Hi,

    Have a look at 'rsync', if the uid/gid's are the same on both boxes, then this was what it was written to do.

    Otherwise a shell script would probably make more sense than AppleScript.

    Casper

     
  3. satyam90 macrumors regular

    satyam90

    Joined:
    Jul 30, 2007
    Location:
    Bangalore, India
    #3
    Use the following shell script.
    Copy the script to "/"
    Now while running script Enter source directory as "oldUsers" and destination directory as "Users"

    Now it will copy all the files from source to destination leaving "Library"

    Code:
    
    #!/bin/sh
    
    echo "Enter Source Directory"
    read src
    echo "Enter Destination Directory"
    read dest
    
    
    list(){
            cd $1
            for files in `ls -al | awk '{print $9}'`
            do
                    if [[ -d $files ]] && [[ ! $files = "Library" ]] && [[ ! $files = "." ]] && [[ ! $files = ".." ]]
                    then
                            createdir=`echo $PWD | sed 's/'$src'/'$dest'/g'`
                            if [[ ! `ls $createdir/$files` ]]
                            then
                                    mkdir -p $createdir/$files
                            fi
                            list $files
                    else
                            if [[ -f $files ]]
                            then
                                    destdir=`echo $PWD | sed 's/'$src'/'$dest'/g'`
                                    cp $files $destdir/$files
                                    echo "#"
                            fi
                    fi
            done
            cd ..
    }
    
    list $src
    
     
  4. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #4
    As an alternative, you could try an AppleScript to do it:
    Code:
    set sourceFolder to choose folder with prompt "Choose the source folder"
    set destFolder to choose folder with prompt "Choose the destination folder"
    set buttonReturned to (display dialog "Preparing to copy all subfolders and files of '" & (the name of (get the info for sourceFolder)) & "' to '" & (the name of (get the info for destFolder)) & "', except the 'Library' folder. Existing folders with the same name will be replaced. Make sure you know what you're doing before proceeding!")
    
    if button returned of result is not "OK" then
    	quit
    end if
    
    tell application "Finder"
    	set subitems to every item in sourceFolder
    	repeat with anItem in subitems
    		if (the name of anItem as string) is not "Library" then
    			duplicate anItem to destFolder with replacing
    		end if
    	end repeat
    end tell
    That's totally untested, by the way. You might run into some permissions problems. At the very least, you'd have to be logged in as root to run it on user folders, I think.
     

Share This Page