实例一:拷贝远程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