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好像是回车的效果

posted @ 2022-02-18 14:37  捏你小脸  阅读(45)  评论(0)    收藏  举报