複数のシステムに並行してscpを実行する方法はありますか?


9

ファイルをすべてのシステムに同時に並行してコピーすることは可能ですか?@のよ​​うに、ファイルはすべてのマシンにコピーする必要があります...

回答:


9

やり方がある。 この Ubuntuのマンページをご覧ください。

名前

   parallel-scp - parallel versions of scp

あらすじ

   parallel-scp [OPTIONS] -h hosts.txt local remote

説明

   pssh provides a number of commands for executing against a group of
   computers, using SSH. It's most useful for operating on clusters of
   homogenously-configured hosts.

   parallel-scp copy files in parallel to a set of machines.

出典:Ubuntu Manpages


6
ここでいくつかの例は素晴らしいでしょう!
ホルヘカストロ

parallel-scp:コマンドが見つかりません
Jonathan

2

はい、parallel-scpをインストールするには、psshパッケージをインストールする必要があります。

sudo apt install pssh 

次に、コマンドが表示されます(man parallel-scpを参照)。

man parallel-scp

NAME
       parallel-scp — parallel process kill program

SYNOPSIS
       parallel-scp [-vAr] [-h hosts_file] [-H [user@]host[:port]] [-l user] [-p par]
       [-o outdir] [-e errdir] [-t timeout] [-O options] [-x  args]  [-X  arg]  local
       remote

DESCRIPTION
       parallel-scp  is a program for copying files in parallel to a number of hosts.
       It provides features such as passing a  password  to  scp,  saving  output  to
       files, and timing out.

OPTIONS
       -h host_file
       --hosts host_file
              Read hosts from the given host_file.  Lines in the host file are of the
              form [user@]host[:port] and can include blank lines and comments (lines
              beginning  with  "#").  If multiple host files are given (the -h option
              is used more than once), then  parallel-scp  behaves  as  though  these
              files  were  concatenated  together.   If  a host is specified multiple
              times, then parallel-scp will connect the given number of times.

       -H     [user@]host[:port]
       --host [user@]host[:port]
       -H     "[user@]host[:port] [ [user@]host[:port ] ... ]"
       --host "[user@]host[:port] [ [user@]host[:port ] ... ]"
              Add the given host strings to the list of hosts.  This  option  may  be
              given  multiple  times,  and  may  be  used  in conjunction with the -h
              option.

       -l user
       --user user
              Use the given username as the default for any host entries  that  don't
              specifically specify a user.

       -p parallelism
       --par parallelism
              Use the given number as the maximum number of concurrent connections.

       -t timeout
       --timeout timeout
              Make  connections  time  out after the given number of seconds.  With a
              value of 0, parallel-scp will not timeout any connections.

       -o outdir
       --outdir outdir
              Save standard output to files in the given directory.  Filenames are of
              the  form  [user@]host[:port][.num]  where  the  user and port are only
              included for hosts that explicitly  specify  them.   The  number  is  a
              counter that is incremented each time for hosts that are specified more
              than once.

       -e errdir
       --errdir errdir
              Save standard error to files in the given directory.  Filenames are  of
              the same form as with the -o option.

       -x args
       --extra-args args
              Passes  extra  SSH  command-line arguments (see the ssh(1) man page for
              more information about SSH arguments).  This option  may  be  specified
              multiple  times.   The  arguments are processed to split on whitespace,
              protect text within quotes, and escape with backslashes.  To pass argu‐
              ments without such processing, use the -X option instead.

       -X arg
       --extra-arg arg
              Passes  a single SSH command-line argument (see the ssh(1) man page for
              more information about SSH arguments).  Unlike the -x option,  no  pro‐
              cessing  is  performed  on  the argument, including word splitting.  To
              pass multiple command-line arguments, use  the  option  once  for  each
              argument.

       -O options
       --options options
              SSH  options  in the format used in the SSH configuration file (see the
              ssh_config(5) man page for more information).  This option may be spec‐
              ified multiple times.

       -A
       --askpass
              Prompt for a password and pass it to ssh.  The password may be used for
              either to unlock a key or for password authentication.  The password is
              transferred  in  a  fairly  secure manner (e.g., it will not show up in
              argument lists).  However, be aware that a root  user  on  your  system
              could potentially intercept the password.

       -v
       --verbose
              Include error messages from ssh with the -i and \ options.

       -r
       --recursive
              Recursively copy directories.

あなたの答えは不完全だと思います。ツールのインストール方法は示しましたが、使用方法は示していません。ここでは質問に答えません。
Eskander Bejaoui

1

ログインするためにパスワードを入力する必要がないように、すべてのターゲットマシンに適切なsshキー構成があると想定して、これを行う方法は次のようになります。

#!/bin/bash
FILE="/put/your/file/here.txt"
TARGET_PATH="/where/to/put/on/remote/system/"
MACHINES="machine1 machine2 machine3"

for current_machine in $MACHINES; do 
   scp $FILE $current_machine:$TARGET_PATH
done

並行して実行するのではなく、次々に実行します。ただし、各コマンドを個別に実行する必要はありません。すべて自動的に実行されます。


それは私がいつもしていることですが、ワンライナーとして:) ... +1(平行ではありませんが)
0xC0000022L

@NiteRainが提案するような&ビハインドを配置する場合scp $FILE $current_machine:$TARGET_PATH、基本的には並列で実行されませんか?
ヘルパーメソッド

はい、うまくいくはずです。
roadmr 2014年

0

このコマンドの使用例をいくつか示します。

  1. インストールsudo apt install psshする場合:次のコマンドが利用可能になります:-

    • parallel-scp:並列プロセスkillプログラム
    • parallel-ssh:並列sshプログラム
    • parallel-rsync:並列プロセスkillプログラム
    • parallel-slurp:並列プロセスkillプログラム
    • parallel-nuke:並列プロセスkillプログラム
  2. 形式に基づく使用法:

    parallel-scp [-vAr] [-h hosts_file] [-H [user @] host [:port]] [-l user] [-p par] [-o outdir] [-e errdir] [-t time- out] [-Oオプション] [-x args] [-X arg] [-L localdir]リモートローカル

    • 使用例:

      1. ホスト名を読み取るhostsファイルを作成します。psshファイルは次の形式になります。

        • [user@]host[:port]、したがってgeorge@192.168.3.30:333

          Each should be on a different line and comments are preceeded by a `#` character
          
      2. 実際のコピーコマンド:

        • parallel-scp -h /path/to/hosts/file src dest
        • すべてのサーバーで$ HOME / demo.txt tp / tmp /をコピーするには:

          parallel-scp -h /path/to/hosts/file $HOME/demo.txt /tmp/
          

ボーナス

  1. すべてのサーバーでコマンドを実行します。

    parallel-ssh -i -h /path/to/hosts/file uptime
    
  2. すべてのサーバーでプロセスを強制終了します。

    parallel-nuke -h /path/to/hosts/file firefox
    

ソース:https : //www.cyberciti.biz/cloud-computing/how-to-use-pssh-parallel-ssh-program-on-linux-unix/

弊社のサイトを使用することにより、あなたは弊社のクッキーポリシーおよびプライバシーポリシーを読み、理解したものとみなされます。
Licensed under cc by-sa 3.0 with attribution required.