shell-scp分发文件夹下所有文件到多台服务器

版权声明:转载请注明出处----------谢谢! https://blog.csdn.net/sinat_36755318/article/details/81392525

#!/usr/bin/expect -f
#chmod 777 distribute_file.sh
#把所有目的ip写入ipfile.txt文件,ipfile.txt文件与distribute_file.sh在同一层目录,ipfile.txt文件中一行写一个ip
#sh distribute_file.sh 源服务器路径   目的服务器路径
#例如:sh distribute_file.sh /home/yxl/ /home/test/test1/
#path: 源服务器路径 
#topath: 目的服务器路径

password=123456
path=$1
topath=$2

while read -r ipline
do
for line in $(ls ${path})
do
expect<<-END
spawn scp ${path}${line} root@${ipline}:${topath}
expect {
        "(yes/no)?" {send "yes\r"; exp_continue}
        "${ipline}'s password:" {send "${password}\r"}
        "Permission denied" { send_user "[exec echo "\nError: Password is wrong\n"]"; exit}
}
expect eof
exit
END
 done
done < ipfile.txt
 

猜你喜欢

转载自blog.csdn.net/sinat_36755318/article/details/81392525