Skip to content

Instantly share code, notes, and snippets.

@alexclifford
Last active January 3, 2016 10:09
Show Gist options
  • Save alexclifford/8447357 to your computer and use it in GitHub Desktop.
Save alexclifford/8447357 to your computer and use it in GitHub Desktop.
Create a new LDAP user - not tested.
#!/bin/bash
LOGDIR="/var/logs"
LOGFILE="ldap-add-user-"$(date +"%F_%H%M")".txt"
LOGPATH=$LOGDIR'/'$LOGFILE
if [ $# -ne 7 ]; then
echo "Usage: ldap_add_user.sh username firstname lastname password organisationunit maildomain authdnuser"
echo "Example: ldap_add_user.sh test.user test user hunter1 ou=Staff,dc=example,dc=com example.com cn=admin,dc=example,dc=com"
exit 0
fi
USERNAME=$1
FIRSTNAME=$2
LASTNAME=$3
PASSWORD=$4
ORGANISATION_UNIT=$5
MAIL_DOMAIN=$6
AUTH_DN_USER=$7
LDAPSCRIPT="dn: uid=$USERNAME,$ORGANISATION_UNIT
objectClass: inetOrgPerson
uid: $USERNAME
sn: $LASTNAME
givenName: $FIRSTNAME
cn: $FIRSTNAME $LASTNAME
displayName: $FIRSTNAME $LASTNAME
userPassword: $PASSWORD
mail: $USERNAME@$MAIL_DOMAIN"
echo "Creating new LDAP user..." 2>&1 | tee -a $LOGPATH
echo "$LDAPSCRIPT" | ldapadd -a -x -D $AUTH_DN_USER -y /etc/ldapscripts/ldapscripts.passwd 2>&1 | tee -a $LOGPATH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment