-
Notifications
You must be signed in to change notification settings - Fork 0
/
search-ad.sh
80 lines (77 loc) · 2.14 KB
/
search-ad.sh
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/bin/bash
usage=$(cat <<-END
Syntax error : [search-ad.sh -X username] options below :
-l <login> = mail info
-g <mail> = login info from email
-a <login> = pager
-e <login> = account expiration
-m <login> = employee ID
-b <login> = room number
-t <login> = phone and mobile
-o <login> = OU
-c <login> = when created
END
)
while getopts ":m:b:t:e:a:l:g:o:c:*:" option; do
case "${option}" in
l)
l=${OPTARG}
email=$(samba-tool user show $l |grep "mail" |awk '{print $2}')
echo "$l - $email"
;;
g)
g=${OPTARG}
login=$(ldbsearch -H /var/lib/samba/private/sam.ldb mail=$g |grep "sAMAccountName" |awk '{print $2}')
echo "$login - $g"
;;
a)
a=${OPTARG}
pager=$(samba-tool user show $a |grep "pager" |awk '{print $2}')
login=$a
echo "$login - $pager"
;;
e)
e=${OPTARG}
expire=$(samba-tool user show $e |grep "accountExpires" |awk '{print $2}')
status=$(samba-tool user show $e |grep "userAccountControl" |awk '{print $2}')
login=$e
echo "$login - $expire - $status"
;;
m)
m=${OPTARG}
employee=$(samba-tool user show $m |grep "employeeID" |awk '{print $2}')
login=$m
echo "$login - $employee"
;;
b)
b=${OPTARG}
bureau=$(samba-tool user show $b |grep "roomNumber" |awk '{print $2}')
login=$b
echo "$login - $bureau"
;;
t)
t=${OPTARG}
phone1="$(samba-tool user show $t |grep "telephoneNumber" |awk '{print $2}')"
phone2="$(samba-tool user show $t |grep "mobile" |awk '{print $2}')"
login=$t
echo "$login - $phone1 - $phone2"
;;
o)
o=${OPTARG}
ou="$(samba-tool user show $o |grep "OU" |awk -F "=|," 'NR==1{print $4}')"
login=$o
echo "$login - $ou"
;;
c)
c=${OPTARG}
created="$(samba-tool user show $c |grep "whenCreated" |awk '{print substr($2, 1, length($2)-9)}')"
login=$c
echo "$login - $created"
;;
*)
echo "$usage"
exit 1
esac
done
if [ $OPTIND -eq 1 ]; then echo "$usage";
fi