0

I have 3 linux servers - the first one is a dev machine (where I compile my binary), the second one is a "jumpbox" which helps me connect to a "testbed" - which is the place where I need to copy my binary.

Right now, I am doing something like this:

1) Copy my binary from devmachine to jumpbox with scp -r binary abc@jumpbox:/temp/

2) Log in to the jumpbox and copy the binary from jumpbok to testbed with scp -r binary abc@testbed:/bin/

Is there some way I can do the above 2 steps thru a single script?

I realize I will be forced to save my passwords in a file for that to work, but I am fine with it - I can always use encryption.

2
  • just a question, can source reach directly serverB ? if yes the question is a bit pointless. – Archemar Mar 25 '15 at 7:27
  • No it cannot .. – Chani Mar 25 '15 at 7:46
2

The easiest option would be, to perform a ssh connection without password via pubkey authentication. That means you have to share the public keys between the servers.

Then you can just use a command like that at the "source" server:

cat file | ssh user@serverA "ssh user@serverB \"cat > file\""
2

you need to set up a password less login, using public/private key with ssh.

then, assuming fles to be copied are in dir,

source$ tar cf - dir | ssh servera 'ssh serverb "cd dest ; tar xf - " '

where

  • source$ is you prompt
  • tar cf - dir tar files in dir to stdin
  • ssh servera logs you to servera
  • cd dest ; tar xf - extract from stdin files in dest dir.
1
  • I was wondering If ssh could be used with port forwarding deom source to server A, then using rsync between source and serverB. – Archemar Mar 25 '15 at 7:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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