1、挂载:mount -t iso9660 -o loop /dev/cdrom /mnt/cd
2、查找expect安装包:yum list | grep expect
3、安装:yum install expect.i686 -y
4、新建并编辑expect配置文件vi expectdemo.sh
配置内容如下:(我这里连接的hadoop02这台虚拟机)
#!/bin/bash/expect
##exp_test.sh
set timeout -1;
spawn ssh hadoop02;
expect {
"(yes/no)" {send "yes\r";exp_continue;}
"password:" {send "123456\r";exp_continue;}
eof {exit 0;}
}
5、执行程序 expect expectdemo.sh可以直接连接到hadoop02这台虚拟机,而不用手动输入yes和密码。