Migrate a NIS password map to LDAP… FAST

I came across this awk hack in an old code repository today. I slapped it together a couple of *years* ago now, and it was never really worthy of being distributed for general use. However, if you’re like me and never made friends with the PADL migration tools and all you need is a quick way to convert a password map, maybe you can use this. If you need to convert a different map, you can use this as a starting point.
If you saved this as ‘nis2ldap’, you’d call it like this:

ypcat passwd | ./nis2ldap > users.ldif

users.ldif, then, would be your new ldif file, hopefully ready to be imported into your LDAP directory. It shouldn’t matter if you use Fedora Directory Server, Novell eDirectory, or OpenLDAP as long as the schema you’re using in your LDIF is supported by the server.


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 ""

See? You don’t really need 20 different perl scripts to do this!
Happy Monday 🙂

Technorati Tags: , , , , , ,

Social Bookmarks: