I have an ldapsearch query to pull some data of an email system, I am trying to parse the data into something I can analyze in a table/flat file, and generate reports on the accounts.
Sample of the ldapsearch output:
# scott, people, example3.org dn: uid=scott,ou=people,dc=example3,dc=org zimbraCOSId: 3f5exxxf-08eb-439a-8d93-cef26b03b722 zimbraMailDeliveryAddress: [email protected] zimbraLastLogonTimestamp: 20161019154312Z zimbraPrefMailForwardingAddress: [email protected] # info, people, example5.org dn: uid=info,ou=people,dc=example5,dc=org zimbraMailDeliveryAddress: [email protected] zimbraCOSId: e2zzy7e74-e4bf-462d-a4b1-7d7b23c31fbe zimbraPrefMailForwardingAddress: [email protected] zimbraLastLogonTimestamp: 20181011075800Z The search command used to pull the test data:
ldapsearch -H $ldap_master_url -w $zimbra_ldap_password -D $zimbra_ldap_userdn -S -LLL -x "(&(objectClass=zimbraAccount)(!(objectclass=zimbraCalendarResource)))" zimbraMailDeliveryAddress zimbraLastLogonTimestamp zimbraPrefMailForwardingAddress | awk '$1=$1' RS= ORS='\n' OFS=';' Here is what I tried:
| awk '$1=$1' RS= ORS='\n' OFS=';' Then I also used grep to prune it down further, but not all records have the same attributes, or the same order so the output is a mess.
Output I am shooting for:
The values of the above attributes in a by row delimited style.
ie:
[email protected],20161019154312Z,[email protected] [email protected],20181011075800Z,[email protected]
Will research if sed can gather the info, since the values are in different order from record to record which seems odd. I have more data fields to add, but very difficult to parse the output.
Thank you
ldapsearchresult for further processing? answers your question? And could you provide your search command, as well what kind of information you are looking for? It might be that other solutions could come in place.