SCP批量传输脚本

8 篇文章 0 订阅

​​​​​​​介绍

SCP(Secure Copy)命令是SSH中最方便有用的命令之一,用于在两台服务器之间直接传送文件。

用法如下:

  • 从本地复制到远程
    • 文件操作:
scp local_file remote_username@remote_ip:remote_folder
  • 目录操作:
scp -r local_folder remote_username@remote_ip:remote_folder
  • 从远程复制到本地
    • 文件操作:
scp remote_username@remote_ip:remote_file local_file
  • 目录操作:
scp -r remote_username@remote_ip:remote_folder local_folder

单台传输

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

多台传输

  • 编写服务器信息文件
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

分享、在看与点赞
只要你点,我们就是胖友

来自: SCP批量传输脚本icon-default.png?t=N7T8https://mp.weixin.qq.com/s?__biz=Mzk0NTQ3OTk3MQ==&mid=2247486027&idx=1&sn=e8524d7e47fb1a481b72ab4c7cba80e5&chksm=c3158207f4620b11e4ed1fe2c6f1e6557136f47c9d7c7eb69a6c0dc8c2880e254e31d1a29787&token=355315523&lang=zh_CN#rd

  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Linux技术宅

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值