expect 实例

实例一:拷贝远程ssh_config文件到/etc/ssh下

#!/bin/bash
while read ip
do
ip=$ip
/usr/bin/expect <<EOF
set timeout 1
spawn  ssh -t username@$ip sudo  mv /home/deployer/ssh_config /etc/ssh/ssh_config
expect "(yes/no)?"  { send "yes\r";exp_continue }
expect   "password:"  { send "mypasswd\r";exp_continue }
expect  "deployer:"  { send "mypasswd\r";exp_continue }
expect eof
EOF
done < ip.txt

  

 

posted @ 2020-03-23 09:56  北漂-boy  阅读(136)  评论(0编辑  收藏  举报