briandoll (owner)

Revisions

gist: 384 Download_button fork
public
Description:
awk ldap query to yaml
Public Clone URL: git://gist.github.com/384.git
Embed All Files: show embed
Bash #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# This is an awk script, but no awk colour coding is available here.
 
#
# input: an LDAP query pulling back the displayName and sAMAccountName properties
# for an entire ActiveDirectory forest
#
# output: yaml format of same data
# ex.
# 1:
# name: "Doll, Brian A"
# lan_id: "brian.a.doll"
 
 
# split on newline for fields
BEGIN { FS = "\n"; RS = "" }
 
# don't deal with incomplete records, gotta have 3 fields
NF == 3 {
 
  name = $2
  lanid = $3
 
  # get rid of the prefixes
  sub(/displayName\: /, "", name)
  sub(/sAMAccountName\: /, "", lanid)
 
  # escape the quotes on familiar names like "Tina" for Christina
  gsub(/"/,"\\\"",name)
 
# get rid of the tabs
gsub(/[\t]/,"",name)
# skip numeric account names
if (!gsub(/^[0-9]/,"",name)) {
 
# print in yaml format
printf("%s:\n name: \"%s\"\n lan_id: \"%s\"\n", NR, name, lanid)
 
  }
}