Moving Users Sites Folders, but Keep Sites Active

Discussion in 'Mac OS X Server, Xserve, and Networking' started by haze, Oct 9, 2009.

  1. haze macrumors regular

    Nov 11, 2007
    So, here is the deal. I have an Xserve that I use as a Web server for my class page and student Web sites. I need to add new students/users for this year and move the old users/sites to a new folder, but still be able to have the sites on-line.

    So, for example:

    On the server I have student xyz (/Users/xyz). The student ftps into their account and uploads their page to their /Sites folder. The student site is now live at

    Each new year I want to be able to to move student xyz and all other students to something like /Sites/0809/xyz and have the URL be:

    Is there a way to do this easily? Seems all of the users folders would have to be moved to /Sites/0809 and then the contents of their /Sites folder needs to be moved to their root directory. (/Users/xyz/Sites becomes /Sites/0809/xyz).
  2. belvdr macrumors 603

    Aug 15, 2005
    For just moving them, if you create a file with one username per line that needs to be moved, you could do this in Terminal:

    # Specify the year directory to move the files to
    # Rotate through a text list of usernames
    for USERNAME in `cat /file_with_usernames_to_be_moved`; do
     # Ensure the new directory exists first
     mkdir -p /Sites/${YEAR}/${USERNAME}
     # Move the user's Sites data to the new folder created above
     mv /Users/${USERNAME}/Sites/* /Sites/${YEAR}/${USERNAME}/
    You can put this code into a text file, say and run it from Terminal whenever needed. You'll just need to update the YEAR variable at the beginning to whatever you want it to be before running (0809, 0910, 1011, etc). Optionally I can edit it for you so you could do:

    Code: 0809
    And it would take the 0809 from the command line.

    To create the file easily for editing, you can use the following from Terminal:

    ls -1d /Users/*/ | cut -d/ -f3 > /path/to/users_to_be_moved
    You'll want to edit the output file (users_to_be_moved) and keep only those users you want.
  3. haze thread starter macrumors regular

    Nov 11, 2007
    I'll have around ~225 students each year that I'll do this for. I figure I will archive back 5-7 years. After that I'll just delete that year's archive folder with all those sites in it.

    Thanks for the terminal workflow. I'll try it out today. I want to move last year's students and make the new accounts so this year's students can upload their sites.
  4. haze thread starter macrumors regular

    Nov 11, 2007
    I am obviously doing something wrong. lol I copied and pasted the contents from the first box into textedit and saved with a .sh extension. Then I ran the last commands and it generated the text files with usernames. Then when I sudo ran it said -bash command not found.

    What am I doing wrong?
  5. calderone macrumors 68040


    Aug 28, 2009

    Unless you placed the .sh in a path bash looks for, you will need to specify where it is.

    For example if you are in the same directory as the script:
    Or you can move it do /bin

    sudo mv /bin/
    Then you can execute it anywhere.

    You should need to set the execute bit to run it though.

    chmod +x
    Hope that helps.
  6. haze thread starter macrumors regular

    Nov 11, 2007
    I'll try that tomorrow. I am not a terminal guru. I cd to the directory and then simply typed sudo

    I use to be a DOS command line pro, but that was a loooooong time ago. I should brush up on unix commands since I have to be the net tech for my Mac lab a swell as the teacher.
  7. haze thread starter macrumors regular

    Nov 11, 2007
    Awesome. Thanks for this, it really helped me out. Any chance there is something as easy to delete all of the folders for a user besides /Sites? I download my rosters, tweak in Excel, import into Passenger, export as tab delimited, tweak again, and then use batch import in Webmin to mass create student accounts on the Web server. This works great, but I really only need a /Sites folder for each user. The only purpose for these accounts is for the students to ftp in and upload their Web site to /Sites. Their full LDAP accounts are on the ODM Xserve.
  8. belvdr macrumors 603

    Aug 15, 2005
    # Rotate through a text list of usernames
    for USERNAME in `cat /file_with_usernames_to_be_moved`; do
    # Remove all directories for that user's folder
    rm -fr /Users/${USERNAME}
    # Recreate Sites folder
    mkdir -p /Users/${USERNAME}/Sites
    # Change permissions on newly created Sites folder
    chown ${USERNAME} /Users/${USERNAME}/Sites
    chmod 755 /Users/${USERNAME}/Sites

Share This Page