我使用了以下内容:
#!/bin/bash
function auto_run
{
/usr/bin/expect<<EOF
#!/usr/bin/expect
proc guest_reboot {} {
send "reboot\r"
expect "login" {
send "root\r"
expect "word:"
send "1234\r"
}
}
spawn ssh user@$1
expect {
"active"
spawn ssh root@$1
expect -re "Escape"
send "\r"
expect "#"
guest_reboot
}
default
{
send "\r"
guest_reboot
}
}
EOF
}
auto_run guest1