VAR1=$(expect -c '
spawn ssh-keygen -t rsa -f '"$SSH_KEY_PATH_ID"' -N '' -q
expect -exact "Generating public/private rsa key pair.\r
Enter file in which to save the key (/root/.ssh/id_rsa):"
sleep 5
send "\r";
expect "Enter passphrase (empty for no passphrase): "
sleep 5
send "\r";
expect "Enter same passphrase again: "
sleep 5
send "\r";
')
这是我在 bash 中响应 ssh-keygen 问题的命令。即使我删除“睡眠”行,此代码也可以在我的机器上运行。但在另一台机器上它不起作用。它给出了错误
send: spawn id exp6 not open
while executing
"send "\r""
问题是什么
更新:我在 ubuntu 上运行良好,但在 Centos 上运行良好。预期版本相同
更新:我修复了它。问题是,使用 _N 选项它提供了一个密码短语,并且使用此代码我将它作为“”。然后它错误地期望。最后一个有效的代码是;
VAR1=$(expect -c '
spawn ssh-keygen -t rsa -f '"$SSH_KEY_PATH_ID"' -q
expect -exact "Generating public/private rsa key pair.\r
Enter file in which to save the key (/root/.ssh/id_rsa):"
send "\r";
expect "Enter passphrase (empty for no passphrase): "
send "\r";
expect "Enter same passphrase again: "
send "\r";
')