Requirement :
Update the LDAP with the NEW Department and NEW PPLM
CSV format in text(dd.csv) :
M0708276,Sudip deb ,sudipc,Solutions,SE,AK Baner,JP Delivery,mgoel
Shell Script :
read-csv.sh
a=1
ldif="tmp.ldif"
final_ldif="final.ldif"
while read line; do
rm -f $ldif
rm -f $final_ldif
#echo $line
echo $line |grep -i "Employee ID">/dev/zero
if [ $? -eq 0 ]
then
echo "First Line"
continue
else
eid=`echo $line|awk -F',' '{print $1}'`
#ename=`echo $line|awk -F',' '{print $2}'`
uid=`echo $line|awk -F',' '{print $3}'`
#dept=`echo $line|awk -F',' '{print $4}'`
designation=`echo $line|awk -F',' '{print $5}'`
pplmid=`echo $line|awk -F',' '{print $6}'`
new_dept=`echo $line|awk -F',' '{print $8}'`
new_pplm=`echo $line|awk -F',' '{print $9}'`
#ldapsearch -h indus.testdomain.com -x -b "ou=People,dc=testdomain,dc=com" "employeeNumber=$eid" dn|grep -v "\#"|grep -v "search:"|grep -v "result:">>$ldif
ldapsearch -h indus.testdomain.com -x -b "ou=People,dc=testdomain,dc=com" "uid=$uid" dn|grep -v "\#"|grep -v "search:"|grep -v "result:">>$ldif
echo -e "changetype: modify\nreplace: peopleManager\npeopleManager: $new_pplm\n-\nreplace: department\ndepartment: $new_dept">>$ldif
#echo -e "-\nreplace: title\ntitle: $designation">>$ldif
#echo $new_pplm
fi
cat $ldif|sed '/^\s*$/d'>>$final_ldif
dos2unix $final_ldif
#a=`expr $a + 1`
#clear
#cat $final_ldif
#-------------------------------------Dont Enable the line --- The line is to update the LDAP-------------------------------
/usr/bin/ldapadd -x -h indus.testdomain.com -D "cn=admin,dc=testdomain,dc=com" -f $final_ldif -w "xxxxxxxx"
#-------------------------------------Dont Enable the line --- The line is to update the LDAP-------------------------------
#if [ "$a" -le 2 ]
# then
# exit
#fi
done < dd.csv