Log in


Forgot your password?
prijatelji LUGoNSa
gnu.gif
linuxzasve.jpg
hulk.jpg
zextras_logo.png
 
You are here: Home / Uputstva / Opšte / Skripte / LDAP / addAlias.sh

addAlias.sh

by lugons last modified Apr 22, 2008 02:21 PM

text/x-sh icon addAlias.sh — text/x-sh, 795 bytes

File contents

#!/bin/bash

if [ $# -lt 2 ]; then
	echo "Usage:$0 <alias>@<domain> <user>@<domain>"
	echo "Alias and user domains don't have to be the same"
	exit 1
fi

ALIAS_USER=`echo "$1" | cut -f 1 -d '@'`
ALIAS_DOMAIN=`echo "$1" | cut -f 2 -d '@'`
USER=$2
DOMAINS=`ldapsearch -LLL -x '(objectClass=organizationalUnit)' ou | grep ^dn`
TMP=`echo $DOMAINS | grep -o "dn: ou=$ALIAS_DOMAIN,dc=ldap"`

read -p "Enter the LDAP password: " -s PASSWORD
echo

function addAlias()
{
	echo "Adding new alias..."
	TEMPFILE=`tempfile`
	sed -e s/korisnik/$USER/g -e s/aliasDomen/$ALIAS_DOMAIN/g -e s/aliases/$ALIAS_USER/g alias.ldif >$TEMPFILE
	ldapadd -w "$PASSWORD" -x -D "cn=root,dc=ldap" -f $TEMPFILE
	rm -f $TEMPFILE
	echo -e "New alias added\n"
}

if [ -z "$TMP" ]; then
	echo "No such domain"
	exit 1
fi
addAlias

Document Actions