1#!/bin/sh 2# 3# $FreeBSD$ 4# 5 6# Modify this to suit your needs. The "$1" is the map name, eg. "auto_master". 7# To debug, simply run this script with map name as the only parameter. It's 8# supposed to output map contents ("key location" pairs) to standard output. 9SEARCHBASE="ou=$1,dc=example,dc=com" 10ENTRY_ATTRIBUTE="cn" 11VALUE_ATTRIBUTE="automountInformation" 12 13/usr/local/bin/ldapsearch -LLL -x -o ldif-wrap=no -b "$SEARCHBASE" "$ENTRY_ATTRIBUTE" "$VALUE_ATTRIBUTE" | awk ' 14$1 == "'$ENTRY_ATTRIBUTE':" { 15 key = $2 16} 17 18$1 == "'$VALUE_ATTRIBUTE':" && key { 19 printf "%s%s", key, OFS 20 key = "" 21 for (i=2; i<NF; i++) { 22 printf "%s%s", $(i), OFS 23 } 24 printf "%s%s", $NF, ORS 25} 26 27# Double colon after attribute name means the value is in Base64. 28$1 == "'$VALUE_ATTRIBUTE'::" && key { 29 printf "%s%s", key, OFS 30 key = "" 31 for (i=2; i<NF; i++) { 32 printf "%s%s", $(i), OFS 33 } 34 printf "%s", $NF | "b64decode -rp" 35 close("b64decode -rp") 36 printf "%s", ORS 37} 38' 39