1

For an automated mailing and to notify user, respective members of a specific group, I am looking for commands or a single command line which provides a list of email addresses and which can be used further.

Currently I am able to look up the directory in a way like:

ldapsearch -h dc.example.com -p 389 -D "EXAMPLE\admin" -x -w "password" -b "DC=example,DC=com" -s sub "(&(objectCategory=person)(objectClass=user)(sAMAccountName=*)(memberOf=CN=Developers,OU=Role_Groups,OU=Groups,DC=example,DC=com))" mail \
| grep "mail:" \
| cut -d " " -f 2 

This gives me the email addresses of all group members condensed, but not in the format for further processing I were looking for.

admin@example.com
developer@example.com
user@example.com
...

How to get the results in one line i.e. comma or semicolon separated?

admin@example.com;developer@example.com;user@example.com;...

Replacing newlines with commas using tr or sed wasn't working (for me).

2

After some research I've found the paste command. So adding

| paste -sd ";"

made it working in the way I was looking for. The final command line I'am using now is

ldapsearch -h dc.example.com -p 389 -D "EXAMPLE\admin" -x -w "password" -b "DC=example,DC=com" -s sub "(&(objectCategory=person)(objectClass=user)(sAMAccountName=*)(memberOf=CN=Developers,OU=Role_Groups,OU=Groups,DC=example,DC=com))" mail \
| grep "mail:" \
| cut -d " " -f 2 \
| paste -sd ";" 

Your Answer

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

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