#!/usr/bin/expect
set passwd "123456" ##建议用密钥,防止口令泄露
set host [lindex $argv 0]
set file [lindex $argv 1]
spawn rsync -avR --files-from=$file / root@$host:/
expect {
"yes/no" { send "yes\r"}
"password:" { send "$passwd\r" }
}
expect eoflist.txt
/tmp/1.txt /usr/local/sbin/2.sh
ip.list
192.168.89.134 192.168.87.167
rsync.sh
#!/bin/bash for ip in `cat /tmp/ip.list` do echo $ip ./rsync.expect $ip /tmp/list.txt done
除了文件的分发外,还可以批量执行命令。
原文:http://blog.51cto.com/juispan/2065683