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?
Use
exp_continuemay help you with this: