I have script to export entries from database to LDAP, I'm exporting their first name and last name and other attributes. I want to add to this script generator usernames of let's say first character of first name and first 5 characters of last name. But there must be also some duplication check, so if user jdoe is presented in LDAP and now I have to add the same combination of first name and last name, I have to add user jdoe2, jdoe3 etc.

I know there is a lot of tips for creating combination for logins - this one for example https://stackoverflow.com/questions/30313217/scripting-username-creation-from-text-file/30313293#30313293 - but how can I check if user jdoe is presented in LDAP and add instead of that jdoe2?

  • Search for the user in the directory and change to the next username if the first one is already found? Or just try and add it, and if you get an error, then switch to another username? I'm not exactly sure if you're asking about some technical issue, or a logical one? And what does [mysql] have to do with this? – ilkkachu May 16 '17 at 12:04
  • So are you suggesting try to add user jdoe and if this ldapadd fail try to add jdoe2 etc? And how can I recognize if that ldapadd failed because duplicate user and not because any other error? – user1928543 May 16 '17 at 12:26
  • Or how can I check if ldapsearch found successfully that user? with $?=0? – user1928543 May 16 '17 at 12:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.