V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
reticentfat
V2EX  ›  Linux

如何跨服务器拷贝指定文件

  •  
  •   reticentfat · Sep 28, 2015 · 5044 views
    This topic created in 3874 days ago, the information mentioned may be changed or developed.
    我想把所有 sh 文件从 a 服务器考到 b 服务器
    locate *.sh 可以找到这些文件
    如何把这些文件传到 scp 当参数
    11 replies    2015-09-28 22:10:24 +08:00
    jarlyyn
        1
    jarlyyn  
       Sep 28, 2015
    man find

    大概是 find -name '*.sh' -exec scp {} xxxx@xxxx:/xxxx \;
    zuo
        2
    zuo  
       Sep 28, 2015
    xargs 这个命令应该好用
    iwannaflytomoon
        3
    iwannaflytomoon  
       Sep 28, 2015
    1) rsync --exclude-from=FILE --include-form=FILE
    2) locate *.sh |xargs -I {} scp {} xxx@xxx://xxxx
    reticentfat
        4
    reticentfat  
    OP
       Sep 28, 2015
    locate *.sh | xargs -i scp {} xxxx@xxxx:/home/gateway/sh_bak
    find / -name '*.sh' -exec scp {} xxxx@xxxx:/xxxx \;
    都可以实现,不过为啥每个文件我都需要输入一遍服务器密码呢
    iwannaflytomoon
        5
    iwannaflytomoon  
       Sep 28, 2015
    scp 想不输入密码,需要生成密钥来 ssh 验证
    wizardoz
        6
    wizardoz  
       Sep 28, 2015   ❤️ 1
    for e in `locate *.sh`
    do
    scp $e user@host_b:/your_target_dir/
    done
    sparkssssssss
        7
    sparkssssssss  
       Sep 28, 2015
    @reticentfat
    先 find / -name *.sh |xargs tar czf sh.tgz 然后 scp
    msg7086
        8
    msg7086  
       Sep 28, 2015
    先搞起 ssh 证书认证,早日放弃密码连接。
    zhangv
        9
    zhangv  
       Sep 28, 2015
    scp
    ceyes
        10
    ceyes  
       Sep 28, 2015   ❤️ 1
    ```

    locate '*.sh' | xargs -i rsync -azh --progress {} user@server:/your/dir/

    ```

    0. 建议先 ssh-copy-id ,免去输入密码。
    1. xargs -i 把管道前的结果交给后面的程序,放到了{}的位置
    2. rsync 用来同步文件,个人喜欢这个命令,当然 scp 也行。

    rsync 的 -z 是压缩,-h 是 human-readable, --progres 是显示进度,不需要可以去掉。
    rsync 有个 --dry-run ,用以不真的执行,方便测试下先。
    quietin
        11
    quietin  
       Sep 28, 2015
    python 的 pexpect 可以解决输密码问题
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   1153 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 101ms · UTC 23:08 · PVG 07:08 · LAX 16:08 · JFK 19:08
    ♥ Do have faith in what you're doing.