1.yum安装expect
yum -y install expect
2.数学shell脚本
#!/usr/bin/expect
spawn ssh root@192.168.245.158
expect {
"(yes/no)?" {send 'yes\r';exp_continue}
"password" {send "123456\r"}
}
expect "]#"
send "ifconfig\r"
send "exit\r"
expect eof