Reputation: 15562
I want to automate command ssh-keygen -t rsa
. What's unique is the command will print out different text under different conditions. For example, if it is the first time, it will output enter passphrase
and enter passphrase again
. otherwise, it will prompt with Overwrite (y/n):
. How to handle this in expect
.
I have tried using pattern action pair, like
expect "enter passphrase" {send "\r"} \
"Overwrite (y/n): " {send "n\r"}
However, it only handles one prompt at a time; how can I handle the prompt enter passphrase again
?
Upvotes: 0
Views: 151
Reputation: 738
Use exp_continue
may help you with this:
expect {
"Overwrite (y/n)?" { send "n\r" ; exp_coninue }
"Enter passphrase" { send "\r" ; exp_coninue }
"passphrase again:" { send "\r" }
}
Upvotes: 1