1. 程式人生 > >Shell分發系統

Shell分發系統

執行 pla shel set ash plain bar 建議 class

rsync.expect

#!/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 eof


list.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


除了文件的分發外,還可以批量執行命令。


Shell分發系統