Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Can you scp a file to multiple locations in the same command?

For example:

scp file.txt user@ip-1.com:, user@ip2.com:

Or would it be more practical to create a bash script that has all the hosts already in it and it would just take a file as the argument?

share|improve this question

3 Answers 3

up vote 4 down vote accepted

Let's say you have a file (destfile.txt) with user@host-values, one on each line. Then you could do like this:

for dest in $(<destfile.txt); do
  scp ourfile.txt ${dest}:remote/path/
done
share|improve this answer
    
This works! Still a handful to type out though. Perhaps there's a way to simplify that. –  Andrew Sep 22 '11 at 21:02
1  
@Andrew, if you change the for-loop into while read dest; do, it will read from standard input. Put it in a script and feed the destfile.txt into it (e.g., ./thescript.sh <destfile.txt). –  Kusalananda Sep 22 '11 at 21:19
    
Thank you. That does simplify it a bit. –  Andrew Sep 22 '11 at 21:24
cat file.txt | tee >(ssh user@ip1.com "cat > file.txt") \
                   >(ssh user@ip2.com "cat > file.txt")

tar cz file1 file2 file3 | tee >(ssh user@ip1.com "tar xz") \
                               >( ... )
share|improve this answer

Looks like a job for parallel-scp - this implements a set of commands that allow for scp commands to be run on multiple systems at once. It will allow for the copying of files in parallel to a set of machines.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.