[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Re: bash script for adding computers
OK, I've gotten this far on the bash script I was writing to add a
machine. It searches the base for uidNumbers, it sorts the numbers from
largest to smallest, takes the first one and adds one to it. No sweat
right?
Here is the kicker,how do you get the data to ldapadd without creating
an ldif file? I've tried an assortment of redirection techniques and
I've also tried the bash "here" document. In theory, this should be
possible but I am having a really tough time figureing out the syntax.
#!/bin/bash
binddn="cn=root,dc=microverse,dc=net"
pw4binddn="passwordgoeshere"
ldaphost="ldap://localhost"
base="ou=Computers,dc=microverse,dc=net"
minimumUID=500
groupnum=421
store=`ldapsearch -LLL -D $binddn -H $ldaphost -b$base -x "(cn=*)"
uidNumber | \
grep uidNumber | \
sed -e 's/^uidNumber:
//' | sort -nr | head -n 1`
#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"
cat $line1 $line2 $line3 $line4 $line5 $line6 $line7 $line8 $line9
$line10 $line11 $line12 > ldapadd -x -D $binddn -w $pw4binddn
echo -e
$line1$line2$line3$line4$line5$line6$line7$line8$line9$line10$line11$line12