-1

I want migrate from openLDAP Authentication to another Authentication methods. My main problem is the sudoers, where I need to manually migrate them.

Thus, I need to create a script for that. I would like to use bash for this. The ldif file contains lines like the following:

dn: cn=Devs, ou=SUDOers, dc=example,dc=com
sudoUser: %devs
sudoCommand: /bin/su - command
sudoCommand: /bin/su - wwwadmin
sudoHost: ALL
description: Developer Admin
objectClass: sudoRole
cn: Devs

So, what I need to do is:

  1. Read the LDIF file.
  2. Extract all lines between dn: and a blank line, OR, between the lines containing cn: Devs

I would like to use embedded BASH commands, grep, awk, sed etc only.

No Python, PHP, Perl etc.

  • Why don't you take the output of only the desired attributes directly to your ldiff file? – Zumo de Vidrio Feb 13 '17 at 11:34
  • Because, I would need to go and perform 100s of LDAP queries. – Peter Feb 13 '17 at 11:59
  • No Perl? No Python? No additional LDAP queries? What's with deliberately choosing the hard way?... – grawity Feb 13 '17 at 12:19
  • 1
    Please note that superuser.com is not a free script/code writing service. If you tell us what you have tried so far (include the scripts/code you are already using) and where you are stuck then we can try to help with specific problems. You should also read How do I ask a good question?. – DavidPostill Feb 13 '17 at 13:10
  • 1
    David, I really don't see the point of your comment. I am not asking someone to write the script of me, thank you. I am asking how to use specific commands. Anyway, I found what I can do and I will answer my own question. – Peter Feb 13 '17 at 14:44
2

OK, I found an easy way using sed:

sed -n '/start_search/,/end_search/p' filename)
  • start_search is the pattern of the first line
  • end_search is the pattern of the last line.

In my case, start_search is 'dn: cn=' and the end_search is '^cn:' or '^$'

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.