expect自动应答
#expect 如果系统没有装有包,要先装包
yum install expect -y
----------------------------------------------------------------------------------------------
脚本样例:
#!/bin/bash
/usr/bin/expect << EOF
set timeoout 10
spawn ssh 192.168.6.221 date
expect {
"*password*" { send "123456\r" }
}
expect eof
EOF
#命令的小解释
#set timeoout 10 #设置超时时间
#spawn ssh 192.168.6.221 date #表示自动应答的方式执行这个命令
#"*password*" { send "123456\r" } #碰到“password” 关键字的时候应答(发送) "123456" , \r好像是回车的效果

浙公网安备 33010602011771号