Micah Baker, the other day asked me about adding a secondary shortname to OD users.
So how do you add a secondary short name? We could use WorkGroup Manger, but I like the command line and automation.
So I use dscl the command line directory services utility. See the dscl man page here
So through a script together.
So how do you add a secondary short name? We could use WorkGroup Manger, but I like the command line and automation.
So I use dscl the command line directory services utility. See the dscl man page here
dscl -u (OD-DIR-ADMIN) -P (PASSWORD) /LDAPv3/(ODMASTER-DN) -append Users/(SHORTNAME) uid (SHORTNAME TO ADD)Micah had first_last as the username, and wanted to add first.last to all his users.
So through a script together.
#!/bin/bash -
# Eden Nelson 3/12/08
# add shortname
#Please set these vars!!!
# OD Master DNS
ODMASTER=
# OD Dir Admin
ODADMIN=
# OD Dir Admin Pass
ODPASS=
#Temp file where usernames are kept
TEMPFILE=/tmp/default.tmp
#Sleep between operations, keep the script from hammering the ODM
SLEEP=3
## ##
# Script Starts Here #
## ##
trap "{ rm -f $TEMPFILE ;}" EXIT SIGINT SIGTERM
dscl /LDAPv3/"$ODMASTER" -list Users > "$TEMPFILE"
cat "$TEMPFILE" | \
while read USERNAME
do
FIRSTNAME=`echo $USERNAME | cut -d'_' -f 1`
LASTNAME=`echo $USERNAME | cut -d'_' -f 2`
dscl -u "$ODADMIN" -P "$ODPASS" /LDAPv3/"$ODMASTER" -append Users/"$USERNAME" uid "$FIRSTNAME"."$LASTNAME"
sleep "$SLEEP"
done
exit 0
No comments:
Post a Comment