Creating bulk home directories

Requirements

  • Microsoft Excel to create data. If creating manually, Excel is not required.
  • Microsoft Word to replace tabs with manual line breaks. If creating manually, Word is not required.
  • VIM

To create the home directories, set permissions and assign user access, we use the following commands and execute them via a shell script. This provides a quick painless way to create the user’s home folder, plus the “Documents” folder to direct Windows users to save into:

An example of the commands is featured below:

mkdir -p /path/to/user/home/userHomeDir/Documents
chgrp -R 1026 /path/to/user/home/userHomeDir
chown -R 2001102 /path/to/user/home/userHomeDir
chmod -R 772 /path/to/user/home/userHomeDir

To create this from existing user information as used in the entry into Active Directory I used the concatenate function once again, with the username (sAMAccountName) and UID (postalCode). Once the information is manipulated to the desired results the spreadsheet should be saved to a tab delimited text file then opened in Microsoft Word. The reason for this is to replace all the tab characters with line breaks. Any editor capable of this will be fine.

Once you have the data sorted out, fire up a terminal one the computer you want the home directories made and issue:

vim /path/to/desired/save/location/fileName

Press i to insert text. Simply copy the text from your text editor, and paste into vim. To exit and save the file, press esc then type :wq!

When returned to the input prompt, enter the following. This will execute the script we created in VIM.

sh /path/to/desired/save/location/FileName

Once the process is finished, you will be presented with the usual input prompt.

Leave a Reply