Skip to content

Instantly share code, notes, and snippets.

@jblaine
Created October 28, 2011 20:26
Show Gist options
  • Save jblaine/1323448 to your computer and use it in GitHub Desktop.
Save jblaine/1323448 to your computer and use it in GitHub Desktop.
Emulating ypcat passwd with ldapsearch + awk
ldapsearch \
-h ldap1.our.org \
-x \
-LLL \
-b ou=People,dc=rcf,dc=our,dc=org \
'objectClass=posixAccount' | \
awk -F': ' 'BEGIN {gecos=""; uid=""; uidnum=""; gidnum=""; home=""; shell=""
;} /^uid: / {uid=$2} /^gecos: / {gecos=$2} /^uidNumber: / {uidnum=$2} /^gidNumbe
r: / {gidnum=$2} /^loginShell: / {shell=$2} /^homeDirectory: / {home=$2} {if (ui
d != "" && uidnum != "" && gidnum != "") {print uid "::" uidnum ":" gidnum ":" g
ecos ":" home ":" shell; uid=""; gecos=""; uidnum=""; gidnum=""; home=""; shell=
"";} } END { print uid "::" uidnum ":" gidnum ":" gecos ":" home ":" shell; }'
# Now go scrub your eyes with a brush.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment