From 74c34e9c4f25183935c64b4a0b03202ef56de23b Mon Sep 17 00:00:00 2001 From: Mike Gabriel Date: Wed, 20 Sep 2017 13:22:17 +0200 Subject: New script 'itzks-hosts'. Convert all LDAP host objects to a list in CSV file format. --- bin/itzks-hosts | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 bin/itzks-hosts (limited to 'bin/itzks-hosts') diff --git a/bin/itzks-hosts b/bin/itzks-hosts new file mode 100755 index 0000000..bb5239b --- /dev/null +++ b/bin/itzks-hosts @@ -0,0 +1,24 @@ +#!/bin/bash + +set -e + +ldapsearch -xLLL "(&(cn=*)(objectClass=ipHost))" \ + cn ipHostNumber macAddress description 2>/dev/null | perl -p0e 's/\n //g' | \ +while read KEY VALUE ; do + case "$KEY" in + dn:) + HOSTNAME= ; IP= ; MAC= ; DESC= ; DN=${VALUE} + OU=$(echo $DN | sed -r -e 's/cn=[^,]+,ou=[^,]+,ou=[^,]+,ou=([^,]+),.*/\1/') + ;; + cn:) HOSTNAME="${VALUE}";; + ipHostNumber:) IP="${VALUE}";; + macAddress:) MAC="${VALUE}";; + description:) DESC="${VALUE}";; + "") + if [ -n "$DESC" ]; then DESC="\"${DESC}\""; fi + echo "${OU},${HOSTNAME},${IP},${MAC},${DESC}" + ;; + esac +done + +exit 0 -- cgit v1.2.3