1.单台
vim server_list.conf
#使用
ip 用户名 密码 源文件 目标文件地址
#!/usr/bin/expect
if {$argc < 2} {
send_user "usage: $argv0 src_file username ip dest_file password\n"
exit
}
##set key [lindex $argv 0]
set src_file [lindex $argv 0]
set username [lindex $argv 1]
set host_ip [lindex $argv 2]
set dest_file [lindex $argv 3]
set password [lindex $argv 4]
##spawn scp -i $key $src_file $username@$host_ip:$dest_file
spawn scp $src_file $username@$host_ip:$dest_file
expect {
"(yes/no)?"
{
send "yes\n"
expect "password:" {send "$password\n"}
}
"password:"
{
send "$password\n"
}
}
expect "100%"
expect eof
2.多台
vim server_list.conf
ip 用户名 密码 源文件 目标文件地址
#!/bin/bash
host_list="server_list.conf"
cat $host_list | while read line
do
host_ip=`echo $line|awk '{print $1}'`
username=`echo $line|awk '{print $2}'`
password=`echo $line|awk '{print $3}'`
src_file=`echo $line|awk '{print $4}'`
dest_file=`echo $line|awk '{print $5}'`
##key=`echo $line|awk '{print $6}'`
##./allscp.sh $key $src_file $username $host_ip $dest_file $password
./allscp.sh $src_file $username $host_ip $dest_file $password
done