2
\$\begingroup\$

As i am learning bash, i have written a small code which is nothing but a simple ldapsearch query which lists all thememberNisNetgroup under Infra_Global netgroup.

I am pulling the list out of the netgroup and iterating over the list with a for loop which works fine. I am just curious if the below code which works fine can have an improvement from the bash standard.

Would appreciate any help on this.

#!/bin/bash
#
NTGRP=$(ldapsearch -h ldapServer -xLL -b "cn=Infra_Global,ou=Netgroup,ou=tdi,o=tdp" | awk '/^memberNisNetgroup/{print $2}'| cut -d"_" -f2-)
    
for netg in $NTGRP ;
    
do
echo "-- $netg --";
    
ldapsearch -h ldapServer -xLL -b "ou=Netgroup,ou=$netg,ou=location,ou=tdi,o=tdp" | awk '/,,/{print $2}' | tr -d '(),'
    
done

Result:

---- SAT-GEN11 ----
inv0602.tdi.tdp.com
inv0557.tdi.tdp.com
\$\endgroup\$

0

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.