If you need to transfer a config file to multiple remote machines, dsh
will make your life easier. Check out my previous post about dsh if you need more info about setting up dsh
.
First, let’s look at the example file we plan on transferring:
$ cat example-file
example file line 1
example file line 2
We will pipe the output of that file to a dsh
group using the -i
and -c
options. Let’s look at the docs for those options first.
--concurrent-shell | -c
Executes shell concurrently.
--duplicate-input | -i
Duplicates the input to dsh process to individual process
that are remotely invoked.
Now, let’s use those options to tee
the contents to a file on the remote servers:
$ cat example-file | dsh -g ex-group -i -c 'tee ~/example-file'
server-2: example file line 1
server-2: example file line 2
server-1: example file line 1
server-1: example file line 2
server-4: example file line 1
server-4: example file line 2
server-3: example file line 1
server-3: example file line 2
You will notice that the output is in random order due to the -c
concurrent option. Let’s check our work using -w
so that the output is in the proper order:
$ dsh -g ex-group -w 'cat ~/example-file'
server-1: example file line 1
server-1: example file line 2
server-2: example file line 1
server-2: example file line 2
server-3: example file line 1
server-3: example file line 2
server-4: example file line 1
server-4: example file line 2