echo $newldif

This produces:

[root@enigma scripts]# ./adduser adlfalj
./adduser: line 42: $newldif: ambiguous redirect
You've got something else going on cause it works on mine.  (Are you
sure that you're using the bash shell?)
[root@enigma scripts]# echo $SHELL
/bin/bash
[root@enigma scripts]#

[todd@fiji ~/tmp]$ cat file1
#!/bin/bash
#
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 ldapadd it executes, returns no error messages but the new record does not show up on the ldap server. Since it works from the command line using an ldif file it logically cannot be an issue of access to the server. Also, no encryption is currently enabled. Now

#
cat > $newldif <<hrdoc
...
description: Machine Account
...

Post the WHOLE script so we can see what you're doing.  If you change
anything make sure you say exactly what you change.
It's a mess so remember, you asked for it. ;-)
I've been doing all kinds of tests to try and figure a way around the problem. The algorithm works like this:

1. Get a list of uidNumbers
2. Sort them.
3. Take the one off the top (the largest)
4. Add one to it.
5. Create the text of a new record using the new uidNumber.


#!/bin/bash

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

#complete=`echo $line1 $line2 $line3 $line4 $line5 $line6 $line7 $line8 $line9 $line10 $line11 $line12`
#ldapsearch -LL -v -D "cn=proxyuser,dc=microverse,dc=net" -H ldap://localhost -b"dc=microverse,dc=net" -x "(cn=proxyuser)"

#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 -x -D $binddn -w $pw4binddn
line1="dn: uid=$1,ou=Computers,dc=microverse,dc=net\n";
line2="objectClass: top\n"
line3="objectClass: account\n"
line4="objectClass: posixAccount\n"
line5="uidNumber: $store\n"
line6="uid: $1\n"
line7="cn: $1\n"
line8="gidNumber: $groupnum\n"
line9="homeDirectory: /dev/null\n"
line10="loginShell: /bin/false\n"
line11="gecos: Machine Account\n"
line12="description: Machine Account\n"

output=$line1$line2$line3$line4$line5$line6$line7$line8$line9$line10$line11$line12

echo -e "$output" | ldapadd -vx -D $binddn -W $pw4binddn

echo -e "$output" > ldapadd -vx -D $binddn -W $pw4binddn

echo -e $output

echo -e $output > test.ldif

#cat $output
#echo $output

#$output <<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


#cat $line1 $line2 $line3 $line4 $line5 $line6 $line7 $line8 $line9 $line10 $line11 $line12 > ldapadd -x -D $binddn -w $pw4binddn

#complt=$line1$line2$line3$line4$line5$line6$line7$line8$line9$line10$line11$line12

#echo `expr $store + 1`




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

Reply via email to