I have the following .cnf
[ policy_match ]countryName = matchstateOrProvinceName = matchorganizationName = matchorganizationalUnitName = optionalcommonName = suppliedemailAddress =[ policy_anything ]countryName = optionalstateOrProvinceName = optionallocalityName = optionalorganizationName = optionalorganizationalUnitName = optionalcommonName = suppliedemailAddress =[client]countryName = stateOrProvinceName = localityName = organizationName = emailAddress =commonName =
Here's the csv headers:
userPrincipalName,displayName,surname,mail,givenName
I need to update the emailAddress and commonName value only under [client] section using the .csv file containing UPN and displayName.
I also need to loop values from csv and update one by so giving me the chance to run another script in between to generate a certificate.
I'm not familiar with bash scripting at all, just starting to learn while building a project.
example:
foreach $upn in $csv { update [client].emailAddress = $upn run_cert_creation_script_here}
I'm trying:
sed -i "s/emailAddress.*/emailAddress=$upn/" "$CONFIG_FILE"
but this will update all matching field in the cnf.
Update:
I was able to write this:
#!/bin/bash# Define the CSV and CNF file pathsCSV_FILE="exportUsers_2024-8-8.csv"CNF_FILE="clientX.cnf"# Read the CSV file line by linewhile IFS=',' read -r userPrincipalName displayName _ _do echo "UPN: $userPrincipalName" echo "Name: $displayName" sudo sed -i "52 s/emailAddress.*/emailAddress = $userPrincipalName/" "$CNF_FILE" sudo sed -i "53 s/commonName.*/commonName = ""\"$displayName\"/" "$CNF_FILE" done < "$CSV_FILE"