...

A bash script for creating student Open Directory accounts

Feb 12, 2015

our sad old OD server
I recently took over the IT Director job at a school that had been without a full-time IT person for almost a year. One of the awesome gifts from the previous IT person was a ten year old iMac with 1GB of RAM acting as the Open Directory server for the whole school. It was running OS 10.6 (Snow Leopard Server). I decided to just start fresh with a new mac mini running Yosemite. I needed to transfer all the student accounts to the new server though so I wrote a bash script for that purpose. The script pulls from a CSV file that has four columns: grad_year, first_name, last_name, user_name. Here is the script in case it is useful to anybody else: The script is pasted below. Here is the github repo: https://github.com/rabbitfighter/OD_user_migrate #!/bin/bash INPUT=student_list.csv OLDIFS=$IFS IFS=, [ ! -f $INPUT ] && { echo "$INPUT file not found"; exit 99; } # set the starting ID to a number higher than the highest current userID ID=1000 while read gradyear fname lname uname do echo "Creating: $fname $lname" dscl -u diradmin -P your_dir_admin_password /LDAPv3/127.0.0.1 -create /Users/$uname echo "Unique ID" dscl -u diradmin -P your_dir_admin_password /LDAPv3/127.0.0.1 -create /Users/$uname UniqueID $ID echo "fname" dscl -u diradmin -P your_dir_admin_password /LDAPv3/127.0.0.1 -create /Users/$uname FirstName $fname echo "lname" dscl -u diradmin -P your_dir_admin_password /LDAPv3/127.0.0.1 -create /Users/$uname LastName $lname echo "real name" dscl -u diradmin -P your_dir_admin_password /LDAPv3/127.0.0.1 -create /Users/$uname RealName "$fname $lname" echo "primary group" dscl -u diradmin -P your_dir_admin_password /LDAPv3/127.0.0.1 -create /Users/$uname PrimaryGroupID 1026 echo "home dir" dscl -u diradmin -P your_dir_admin_password /LDAPv3/127.0.0.1 -create /Users/$uname NFSHomeDirectory /Users/$uname echo "password" dscl -u diradmin -P your_dir_admin_password /LDAPv3/127.0.0.1 -passwd /Users/$uname "$uname" echo "comment" dscl -u diradmin -P your_dir_admin_password /LDAPv3/127.0.0.1 -create /Users/$uname Comment "$gradyear" ((ID++)) echo $ID done < $INPUT IFS=$OLDIFS

< back