Hi all,
I need to copy a file through multiple hosts using ssh. The number of
hosts I have to go through can vary from 1 to n. I tried this:
cat filename | ssh host1 ssh host2 ssh host3 "cat > filename"
but it doesn't work because the > needs to be escaped. So I tried this:
cat filename | ssh host1 ssh host2 ssh host3 "cat \> filename"
which works great, except it is not consistent because if there is only
one host then I do not need to escape the >. So I tried this:
cat filename | ssh host1 'ssh host2 "ssh host3 'cat \> filename'"'
(alternating single and double quotes)
except this is even more inconsistent about when the > needs to be
escaped and when not.
Is there an elegant solution to this?
I've thought of a couple solutions, but I don't like them too much:
Solution 1. Create a program called save_stdin which will copy from
stdin to a file that is passed as a command line argument. Then I won't
have to worry about escaping anything.
Solution 2. Set up port forwarding first and then copy the file:
Step 1: ssh -g -L 9000:host1:9000 host1 ssh -g -L 9000:host2:22 host2
Step 2: cat filename | ssh -p 9000 localhost "cat > filename"
--
Phillip Hellewell <[EMAIL PROTECTED]>
____________________
BYU Unix Users Group
http://uug.byu.edu/
___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list