rleyba828
asked on
Need help with Bash script to manipulate a text file of AD users
Hi Team,
I just need some assistance with doing a snippet of bash code to prep the output of my filtered ldapsearch query so it is suitable for import to my nosql database.
My original plain text file looks something like this:
...and I want a script to "append" the groupname of the DN to each member of that group (whether the line following is "member:" or "memberOf:") but not to append when the line starts with "description" or any other word.
The output I want is something like this (my delimiter below will be two dashes):
Thanks Very much.
I just need some assistance with doing a snippet of bash code to prep the output of my filtered ldapsearch query so it is suitable for import to my nosql database.
My original plain text file looks something like this:
dn: CN=Marketing,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Mark J,OU=Business Development,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Gina A,OU=Business Development,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Bill C,OU=Business Development,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Jack D,OU=Business Development,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Sally S,OU=Business Development,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com
dn: CN=Sales,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Dana K,OU=Treasury,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Jason M,OU=Customer Service,OU=Operations,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com
dn: CN=Test,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
description: Testing group
memberOf: CN=Globat-VMs,OU=Global,OU=Applications,DC=mycompany,DC=com
member: CN=Alona C,OU=DisabledUsers,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Bill C,OU=Business Development,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Alyson H,OU=Accounting,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Keiran S,OU=Accounting,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com
dn: CN=VirtualCentre-technicians,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
description: Operator Group for VMs
memberOf: CN=Globat-VMs,OU=Global,OU=Applications,DC=mycompany,DC=com
...and I want a script to "append" the groupname of the DN to each member of that group (whether the line following is "member:" or "memberOf:") but not to append when the line starts with "description" or any other word.
The output I want is something like this (my delimiter below will be two dashes):
dn: CN=Marketing,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Mark J,OU=Business Development,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com--CN=Marketing,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Gina A,OU=Business Development,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com--CN=Marketing,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Bill C,OU=Business Development,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com--CN=Marketing,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Jack D,OU=Business Development,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com--CN=Marketing,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Sally S,OU=Business Development,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com--CN=Marketing,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
dn: CN=Sales,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Dana K,OU=Treasury,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com--CN=Sales,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Jason M,OU=Customer Service,OU=Operations,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com--CN=Sales,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
dn: CN=Test,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
description: Testing group
memberOf: CN=Global-VMs,OU=Global,OU=Applications,DC=mycompany,DC=com--CN=Test,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Alona C,OU=DisabledUsers,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com--CN=Test,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Bill C,OU=Business Development,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com--CN=Test,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Alyson H,OU=Accounting,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com--CN=Test,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
member: CN=Keiran S,OU=Accounting,OU=Users,OU=US,OU=Region,DC=mycompany,DC=com--CN=Test,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
dn: CN=VirtualCentre-technicians,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
description: Operator Group for VMs
memberOf: CN=Globat-VMs,OU=Global,OU=Applications,DC=mycompany,DC=com--CN=VirtualCentre-technicians,OU=Groups,OU=US,OU=Region,DC=mycompany,DC=com
Thanks Very much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER