I am reading a csv file containing list of employees(GRCLOGIN.csv) and retrieving employee ID to Query LDAP to retrieve their related data and save it to a text file(LDAP_USERS.txt)
from sys import exit
import subprocess, sys
import csv
with open('GRCLOGIN.csv', 'r') as file:
reader = csv.reader(file, quoting=csv.QUOTE_NONE, skipinitialspace=True)
reader = csv.reader(file)
output = open('LDAP_USERS.txt', 'a')
next(reader)
for row in reader:
val=row[0]
This is where I am getting issue, my objective is only to retrieve employee's firstName and Email, not all details/columns, but when I include firstname and email in the query below , empty text file is generated, but if I remove firstname and email then text file is generated with all employees details correctly but I don't want all details.
I feel issue is where $1 is not correctly being set to str(val) which is employee ID
subprocess.Popen(["./ldapsearch -B -1 -T -h localhost -p 1389 -D 'cn=directory manager' -j ../../bin/passwordfile.txt -b '(GRCLoginID=$1)' firstName email"+str(val)], stdout=output, stderr=output, shell=True)
exit()
f'ldapsearch -h localhost -p 1389 -D "cn=directory manager" -y ../../bin/passwordfile.txt "(GRCLoginID={val})" firstName email'?