系统环境
centos7
yum -y install expect
shell脚本
#!/usr/bin/expect
spawn ssh root@192.168.190.129
#执行命令
expect
{
"(yes/no)?"{ send "yes/r";exp_continue}
#匹配关键字后执行命令
"password:"{ send "123456\r"}
}
expect"]#"
send "ifconfig\r"
send "exit\r"
#退出
expect eof