need script for smbldap-useradd/setquota/ldapadd

Hello guys,

I am trying to add users to samba/ldap system, set their quota, set them a common password and add auto_home records for the new users

User list file is in below format

Firstname Lastname Username

Command I run to add user is

smbldap-useradd -a -m -N $Firstname -S $Lastname $USERNAME

Password is set using

smbldap-passwd $USERNAME

Currently I have below working only to set passwords.

#!/bin/bash

ChangePasswd()
{
/usr/bin/expect <<EOF
spawn smbldap-passwd $user
expect "New password: "
send -- "$2\r"
expect "Retype new password: "
send -- "$2\r"
expect eof
EOF
}
#while read -p "Enter Userid:" user
while read user
do
if [[ $user != '' ]];
then
ChangePasswd $user $1
fi
done < usernames

./changepassword <common password>

Then I'd like to set quota to 100MB,

setquota -u $USERNAME 0 100000 0 0 /

Finally, I want to add auto_home records for all users,

ldapadd -v -x -D 'cn=admin,dc=blah' -w <admin password> -f /tmp/temp.$USER.ldif

cat > /tmp/temp.$USER.ldif <<EOF
dn: cn=$USER,ou=auto_home,dc=blah
objectClass: automount
automountInformation: -rw,hard,intr <IPOFNFSSERVER>:/export/$USER
cn: $USER
EOF

I'd like to have the script remove /tmp/temp.$USER.ldif after done.

Can anyone help me to combine all in a single bash script. This is going to be used on an ubuntu system.

Thanks much!