使用expect 下的spawn命令

expect << EOF
set timeout 5
spawn ssh -l $hostuser $hostaddr
expect {
"yes/no)?" { send "yes\r";exp_continue }
"assword:" { send "$passwd\r" }
}
expect "$hostuser*"
send "ssh-keygen -t rsa\r"
expect "Enter file in which to save the key*"
send "\r"
expect {
"(y/n)?" { send "n\r";exp_continue }
"Enter passphrase*" { send "\r";exp_continue }
"Enter same passphrase again:" { send "\r" }
}
interact
EOF

版权声明:本文为qq_20962187原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
原文链接:https://blog.csdn.net/qq_20962187/article/details/81634455