summaryrefslogtreecommitdiff
path: root/bin/itzks-hosts
diff options
context:
space:
mode:
Diffstat (limited to 'bin/itzks-hosts')
-rwxr-xr-xbin/itzks-hosts24
1 files changed, 24 insertions, 0 deletions
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