Can you scp a file to multiple locations in the same command?
IE. 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?

link|improve this question
feedback

2 Answers

up vote 1 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
link|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
@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
feedback
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") \
                               >( ... )
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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