I am trying to run a shell script with “except” module for executing the below command
[user1@scds2000025np certificate_renew]$ keytool -import -alias rootca0606 2024 -file 25npBaseDomainRootCA06062024.cer -keystore OBG-ST-APIIdentity.jks -tr ustcacerts
Enter keystore password:
Certificate already exists in keystore under alias <rootca05062024>
Do you still want to add it? [no]:
The shell script I am trying is
#!/bin/bash
# Move to the specified directory
cd /data/user1/certificate_renew/
# Define variables
KEYTOOL_COMMAND="keytool -import -alias rootca06062024 -file 25npBaseDomainRootCA06062024.cer -keystore OBG-ST-APIIdentity.jks -trustcacerts"
KEYSTORE_PASSWORD="password"
# Create the expect script
expect <<EOF
# Set timeout (in seconds)
set timeout -1
# Spawn the keytool command
spawn $KEYTOOL_COMMAND
# Expect the keystore password prompt
expect "Enter keystore password:"
send "$KEYSTORE_PASSWORDr"
# Handle subsequent prompts
expect {
# Match any string for the alias part
-re {Certificate already exists in keystore under alias <.*>rnDo you still want to add it? [no]:} {
send "yesr"
exp_continue
}
eof
}
# Interact with the spawned process
interact
EOF
But while executing the shell script “yes” is not getting applied for the second confirmation and it is waiting in the prompt. The result is as below
spawn keytool -import -alias rootca06062024 -file 25npBaseDomainRootCA06062024.cer -keystore OBG-ST-APIIdentity.jks -trustcacerts
Enter keystore password: password
Certificate already exists in keystore under alias <rootca05062024>
Do you still want to add it? [no]:
Is there wany I can get the second prompt also applied