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
";exp_continue }
expect   "password:"  { send "mypasswd
";exp_continue }
expect  "deployer:"  { send "mypasswd
";exp_continue }
expect eof
EOF
done < ip.txt

  

原文地址:https://www.cnblogs.com/yjt1993/p/10340524.html