Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

scp a data file over two hops..... 2

Status
Not open for further replies.

jdespres

MIS
Aug 4, 1999
230
US
I would like to scp a file automatically from server1 to server2....

But can't go from server1 to server 2....

Server1 & server2 can talk to server3...

How can I automate moving a data file over multiple hops...

server1 --> server3 --> server2

Thanks...

Joe Despres
 
server1 -> server2 <- server3

push data from server1 to server2, then at another time pull data from server2 to server3.

or write a script that waits for new files to show up in a directory and when it sees something new it scp's on to server3

 
or, thinking about it for a second you could maybe set up an ssh tunnel on server2 to fwd a port on to server3.

you'd need to go google ssh tunneling though, been too long since i did anything like that.
 
That worked great!!!!!

That dumped the file to my home dir....

How can I dumpit to another dir?

Thanks....

Joe Despres
 
I got this to work:

ssh server 3 'ssh server2 "cd /another/dir/ && cat > destfile"' < srcfile

Thanks....

Joe Despres
 
-* sigh *-

if it isn't one problem... it's another!

Now I can't pass a varible on the command!

ssh server 3 'ssh server2 "cd /another/dir/ && cat > $server.destfile.$Date.html"' < $server.srcfile.$Date.html

Thanks....

Joe Despres
 
that is clever Annihilannic, hadn't thought of that.

Joe, i imagine it's not working for you now because of the single quotes wrapped around the ssh to server2, you could maybe get away without using the single quotes.

ssh server3 "ssh server2 cat >$variable.$file" <$variable.$file
 
ok nevermind, i tested and that doesnt work.. you'd have to set your variables inside the single quotes for them to be used.

ssh server3 'server=elbert;destfile=destfile;ssh server2 "cd /tmp && cat >$server.destfile"' <$srcfile

i've never had much luck nesting/passing anything complex through ssh on the commandline.

 
This should do it Joe, although we're starting to descend into quote-hell here....

Code:
ssh server3 "ssh server2 \"cat > /another/dir/$server.destfile.$Date.html\"" < $server.srcfile.$Date.html

Annihilannic.
 
Thanks!!!

This was a success!

The variable was passed....

Thanks again!

Joe Despres
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top