23,128
社区成员
发帖
与我相关
我的任务
分享
#向指定的服务器复制文件或目录
#参数1:ip地址;参数2:登录用户名;参数3:登录密码;参数4:发送的文件;参数5:目标位置
function scptoremote() {
local ip=$1
local username=$2
local password=$3
local sendfiles=$4
local toplace=$5
/usr/bin/expect<< EOF
log_user 0
set timeout 1
spawn scp -r $4 ${username}@${ip}:${toplace}
expect {
"*No route to host" {exit 12;exp_continue}
"*Name or service not known" {exit 12;exp_continue}
"*yes/no*" {send "yes\r";exp_continue}
"*password:" {send "${password}\r";exp_continue}
"Permission*" {exit 1;exp_continue}
"\\\\\\- *" {exit 13}
}
expect eof
EOF
return $?
}
[root@master shfile]# scptoremote 192.168.199.233 root abcdefg ~/.ssh/ ~/.ssh/