使用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

你可能感兴趣的:(使用expect 下的spawn命令)