您好,欢迎来到化拓教育网。
搜索
您的当前位置:首页通过scp传输文件到多个主机

通过scp传输文件到多个主机

来源:化拓教育网

#!/usr/bin/bash
DEBUG=true
debug(){
if [ "$DEBUG" = "true" ];then
$@
fi
}
func_expect(){
expect -c "
set timeout 30;
spawn $*;
expect {
\"(yes/no)?\" {send \"yes\r\";exp_continue}
\"*ssword:\" {send \"$pass\r\";exp_continue}
#\"*~]\$\" {send \"df -h\r exit\r\";interact}
}
"
}
func_exec(){
#command="scp $1 $2@$3:."
command="scp $1 $2@$3:./agent/bin/"
debug echo '$command' : $command
func_expect $command
}
if [ $# -ne 2 ];then
echo -e "\nwrong call !\nfor eample: $0 file cfg\n"
exit 1
else
dir='.'
debug echo '$dir' : $dir

file1=$dir/$1

debug echo '$file1' : $file1

debug echo '$#': $#
cat $2 | grep -v '^#' | awk '{print $1,$2,$3,$4}' | while read type ip user pass
do
func_exec $file1 $user $ip
sleep 1
done
fi

 

$1:要传输的文件

$2:主机信息 如: ssh 127.0.0.1 user password

转载于:https://www.cnblogs.com/wcc331902579/p/5912833.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo9.cn 版权所有 赣ICP备2023008801号-1

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务