#!/bin/bash
rm -rf ~/.ssh/known_hosts
#删除文件后,ssh远程任何主机都会询问是否确认要连接该主机
expect <<EOF
# <<EOF表示开始交互 EOF end of file
spawn ssh 192.168.4.254
#根据真实情况输入主机的ip地址
expect "yes/no" {send "yes/r"}
expect "#" {send "yum -y install httpd\r"}
expect "#" {send "exit/r"}
EOF
#结束交互