Copy a file to multiple hosts simultaneously
A simple task (with a simple solution): copy a file to many hosts
using say scp
. The hosts to copy to are in a text file hosts.txt
.
There are many ways to do this, but the following way has the
advantage that it is easy to use and that files are copied
simultaneously (control the maximum parallelism with the -j
switch) which, if you have many hosts, can be a very large saving in
time:
xargs -a hosts.txt -d "\n" parallel -i scp testfile.txt {}:~/ --
Here parallel
is GNU
Parallel
which on Debian/Ubuntu is in the moreutils
package.