I am trying to generate certificate request and submit to CA through bat file.
I am able to do it for just 1 hostname so I am doing a bat file to generate all these automatically. Here's what I've tried. It is supposed to loop through line by line in the hostnames.txt file and replace all the variables.
Referencing from How do you loop through each line in a text file using a windows batch file?
set CA_SERVER=xxxx
set CA_NAME=xxxx
set LOGFILE=.\RequestCert.log
set LIST=hostnames.txt
if not exist %LIST% (
echo %DATE% : %TIME% : ERROR : The list of hostnames file %LIST% is
missing. Cannot request certificate. Exiting! >> %LOGFILE% )
for /f "tokens=*" %%a in ("%LIST%") do (
set HOSTNAME=%%a
echo HOSTNAME
)
I want to test if a simple echo will work but the error came up as: The syntax of the command is incorrect. I saw many references from stackoverflow but it can't figure out what is wrong.
Below is what I will implement after the above is fixed.
openssl req -nodes -newkey rsa:2048 -nodes -keyout %HOSTNAME%.key -out
%HOSTNAME%.csr -subj "/C=SG/ST=/L=xxx/O=xxx/OU=xxx
/CN=%HOSTNAME%"
certreq -submit -f -config "%CA_SERVER%\%CA_NAME%" -attrib
CertificateTemplate:SSLCert" %HOSTNAME%.csr
echo Generating certificate request and key for %HOSTNAME%
I know this has been asked many times but mine doesn't seem to work.. Thank you in advance for your help!
UPDATE:
Current configuration which works after help from Gerhard Barnard.