: !/bin/sh . /u/catcom/ldap_vars ###################### LDAPURI="$WB_LDAPURI" LDAPHOST="$WB_LDAPHOST" LDAPPORT="$WB_LDAPPORT" BINDDN="$WB_BINDDN" BINDPW="$WB_BINDPW" BASEDN="$WB_BASEDN" #srchcn="robynd" #FILTER="(sAMAccountName=$srchcn)" #surname="douglas" #firstname="robyn" #FILTER="(sn=$surname,givenName=$firstname)" #srchcn="douglas*robyn" #FILTER="(cn=*$srchcn*)" email="$1" #email="robyn.douglas@victrack.com.au" #echo "# email=\"$email\"" FILTER="(mail=$email)" #FILTER="" echo "# FILTER=[$FILTER]" #ldapsearch -L -h $LDAPHOST -p $LDAPPORT \ # -x -D "$BINDDN" -w "$BINDPW" \ # -b "$BASEDN" \ # "$FILTER" \ # cn distinguishedName displayName mail #ldapsearch 2>&1 -d 9 -L -h $LDAPHOST -p $LDAPPORT \ # -x \ # -ZZ \ if [ -n "$LDAPURI" ];then HOSTARG="-H $LDAPURI" else HOSTARG="-h $LDAPHOST" fi if [ -n "$LDAPPORT" ]; then PORTARG="-p $LDAPPRT" else PORTARG="" fi #if [ -n "$BINDDN" ]; then # BINDARG="-D $BINDDN" # if [ -n "$BINDPW" ]; then # BINDARG="$BINDARG -w $BINDPW" # fi #else # BINDARG="" #fi # "cn distinguishedName displayName title telephoneNumber facsimileTelephoneNumber department company sAMAccountName mail manager mobile extensionAttribute1" # unwrap warped lines in ldapserach output fixldapsearchoutput() { awk ' { gsub(/\\/,"/",$0) if ( substr($0,1,1) == " " ) { lastline = lastline substr($0,2) next } if ( plast == 1 ) { print lastline lastline = "" plast = 0 } lastline = $0 plast = 1 } END { if ( plast == 1 ) print lastline }' } #----------------------------------- #echo "ldapsearch 2>&1 -d 0 -x -L $HOSTARG $PORTARG \ # -b \"$BASEDN\" \ # -D \"$BINDDN\" -w \"$BINDPW\" \ # \"$FILTER\" \ # \"mail\" \ # \"sAMAccountName\" \ # \"extensionAttribute1\" \ #" #ldapsearch 2>&1 -d 0 -x -L $HOSTARG $PORTARG $BINDARG \ # -b "$BASEDN" \ # -D "$BINDDN" -w "$BINDPW" # "$FILTER" \ # "mail" \ # "sAMAccountName" \ # "extensionAttribute1" #exit 0 ( ldapsearch 2>&1 -d 0 -x -L $HOSTARG $PORTARG \ -b "$BASEDN" \ -D "$BINDDN" -w "$BINDPW" \ "$FILTER" \ "mail" \ "sAMAccountName" \ "extensionAttribute1" \ 2>&1) | fixldapsearchoutput | \ while read af1 arest do #echo "$0: af1=[$af1] arest=[$arest]" 1>&2 if [ "$af1" = "mail:" ]; then mail="$arest" echo "mail=\"$mail\"" fi if [ "$af1" = "sAMAccountName:" ]; then sAMAccountName="$arest" echo "sAMAccountName=\"$sAMAccountName\"" fi if [ "$af1" = "extensionAttribute1:" ]; then extensionAttribute1="$arest" echo "extensionAttribute1=\"$extensionAttribute1\"" #//s-vm-sp01/photo$/ROBYND.jpg awk -v"extensionAttribute1=$extensionAttribute1" ' BEGIN { split(extensionAttribute1,pic_arr,"/") printf("pic_arr3=\"%s\"\n", pic_arr[3]) printf("pic_arr4=\"%s\"\n", pic_arr[4]) printf("pic_arr5=\"%s\"\n", pic_arr[5]) exit(0) }' fi done exit 0