-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Jim C wrote on Tue, Jan 14, 2003 at 07:28:07PM -0800 :

> >newldif="./file2"
> Herein lies part of the problem.
> I don't want to use a file for scaleability reasons and I can't think of 
> any reason why it should be nescesary.  In theory I should be able to 
> store all of the text in a shell variable and then redirect the output 
> of echo to ldapadd.  So far I can get the text in but when I pass it to 

You're right, this is part of the problem.  Shell variables don't keep
the newline characters.  Witness:

[todd@fiji ~/tmp]$ cat file1 
#!/bin/bash

TEMP="line1
line2
line3"

echo $TEMP
[todd@fiji ~/tmp]$ ./file1 
line1 line2 line3

I don't see why you just don't do this:

#!/bin/bash

if [ ! $1 ]; then
        echo "Sorry, you must pass the userid to add to directory."
        exit 1
fi

binddn="cn=root,dc=microverse,dc=net"
pw4binddn="[deleted for security]"
ldaphost="ldap://localhost";
base="ou=Computers,dc=microverse,dc=net"
basetest="ou=People,dc=microverse,dc=net"
minimumUID=501
groupnum=421

# 1. Search the LDAP database and return all uidNumber attributes in a 
# given base

store=`ldapsearch -LLL -D $binddn -H $ldaphost -b$base -x "(cn=*)" uidNumber | \
         grep uidNumber | \
         sed -e 's/^uidNumber://' | sort -nr | head -n 1`

newtest=`ldapsearch -LLL -D $binddn -H $ldaphost -b$basetest -x "(cn=*)" uidNumber | \
         grep uidNumber | \
         sed -e 's/^uidNumber://' | sort -nr`
echo ${newtest[0]}

#It is best not to start at 0 or 1 as these could be privledged.

if [ "$store" = "" ]
        then
        store=$minimumUID
else
        store=`expr $store + 1`
fi

LDAPADD="ldapadd -vx -D $binddn -W $pw4binddn"

$LDAPADD <<hrdoc
dn: uid=$1,ou=Computers,dc=microverse,dc=net
objectClass: top
objectClass: account
objectClass: posixAccount
uidNumber: $store
uid: $1
cn: $1
gidNumber: $groupnum
homeDirectory: /dev/null
loginShell: /bin/false
gecos: Machine Account
description: Machine Account
hrdoc

echo `expr $store + 1`

Blue skies...                   Todd
- -- 
 Todd Lyons -- MandrakeSoft, Inc.   http://www.mandrakesoft.com/
 Favourite shell:  bash, though I also like 'init=/usr/bin/emacs'
                                                --Andrew Tridgell
   Cooker Version mandrake-release-9.1-0.1mdk Kernel 2.4.20-2mdk
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.1 (GNU/Linux)

iD8DBQE+JZ2clp7v05cW2woRAg2MAJwPtm26YsK8sFRccdmRYkHuFECsCACgynvb
43Dip0+6exTBJitKBjZHjP4=
=/76n
-----END PGP SIGNATURE-----

Want to buy your Pack or Services from MandrakeSoft? 
Go to http://www.mandrakestore.com

Reply via email to