Quick NIS passwd to LDAP script
I found this awk script while browsing around on the web. I was looking for a simple way to migrate an NIS+ passwd file to LDAP config and this is what I found. Unfortunately, when I went to cut and paste it into a script on my server, I realized it had a bunch of smart quotes in it. So, here is a cleaned up version:
#!/bin/bash
awk -F: '{
print "dn: cn="$1",ou=People,dc=mydomain,dc=com"
print "objectClass: top"
print "objectClass: person"
print "objectClass: organizationalPerson"
print "objectClass: inetOrgPerson"
print "objectClass: posixAccount"
print "objectClass: inetLocalMailRecipient"
print "objectClass: shadowAccount"
print "uid: "$1
gfields = split($5,gecos,",")
namefield = split(gecos[1], fullname, " ")
print "sn: " fullname[namefield]
print "givenName: "fullname[1]
print "cn: " $1
print "userPassword: {crypt}"$2
print "loginShell: "$7
print "uidNumber: "$3
print "gidNumber: "$4
print "homeDirectory: "$6
print "gecos: "$5
print "mail: "$1"@mydomain.com"
print "displayName: " gecos[1]
print ""
}'
Follow m0j0’s instructions for using it from the link above — and don’t forget to change the mydomain string, if necessary. I also found it helpful to capture my NIS passwd info into a file before running this script. It gave me a chance to remove old stuff I didn’t need anymore. To do that, just ypcat passwd > nis_passwd, make your edits, and then cat nis_passwd | nis2ldap > users.ldif.
Thanks, m0j0!
Filed in Technology One Response so far