#!/bin/tcsh ## Use this script to generate a text file with all information necessary to make a flat BSD passwd file ## The file generated will then have the excess information edited using awk (see below) # ## Generate a list of user names and put then in a text file called UserName.txt # sudo dscl localhost -list /LDAPv3/127.0.0.1/Users > ~/Desktop/UserNames.txt # ## Generate a text file with user data by querying the LDAP database with parsed data from UserNames.txt # foreach student ( `cat ~/Desktop/UserNames.txt` ) sudo dscl localhost -read /LDAPv3/127.0.0.1/Users/$student | grep -w "uid" >> ~/Desktop/UserList.txt sudo dscl localhost -read /LDAPv3/127.0.0.1/Users/$student | grep -w Password >> ~/Desktop/UserList.txt sudo dscl localhost -read /LDAPv3/127.0.0.1/Users/$student | grep "UniqueID: " >> ~/Desktop/UserList.txt sudo dscl localhost -read /LDAPv3/127.0.0.1/Users/$student | grep "PrimaryGroupID: " >> ~/Desktop/UserList.txt sudo dscl localhost -read /LDAPv3/127.0.0.1/Users/$student | grep "cn: " >> ~/Desktop/UserList.txt sudo dscl localhost -read /LDAPv3/127.0.0.1/Users/$student | grep -w "NFSHomeDirectory: " >> ~/Desktop/UserList.txt sudo dscl localhost -read /LDAPv3/127.0.0.1/Users/$student | grep -w "UserShell: " >> ~/Desktop/UserList.txt end # ## awk text formatting # ## Removes all unwanted text except line breaks using gsub (substitute): # awk '{gsub("uid: |Password: |UniqueID: |PrimaryGroupID: |cn: |NFSHomeDirectory: |UserShell: ",":");print $0}' ~/Desktop/UserList.txt > ~/Desktop/UserList-2.txt # ## Replace all but 7th line break with triple-commas: awk 'ORS= NR%7?",,,":"\n"' ~/Desktop/UserList-2.txt > ~/Desktop/UserList-3.txt # ## Remove all colons: awk '{gsub(":","");print $0}' ~/Desktop/UserList-3.txt > ~/Desktop/UserList-4.txt # ## Replace triple-commas with colons awk '{gsub(",,,",":");print $0}' ~/Desktop/UserList-4.txt > ~/Desktop/UserList-FINAL.txt # ## Clean up UserLists rm -rf ~/Desktop/UserNames.txt rm -rf ~/Desktop/UserList.txt rm -rf ~/Desktop/UserList-2.txt rm -rf ~/Desktop/UserList-3.txt rm -rf ~/Desktop/UserList-4.txt exit 0