1

The scenario is like:

SERVER_A="servera.com"
SERVER_A_UNAME="usera"
SERVER_B="serverb.com"
SERVER_B_UNAME="userb"

I want to write a shell script which will fist connect to server A, and then only it would be connected to server B. Like:

#!/bin/sh
ssh $SERVER_A_UNAME@$SERVER_A ...and then
ssh $SERVER_B_UNAME@$SERVER_B

But I am not able to do it. It does connect to server A only. How can I achieve it?

Workonphp
  • 1,635
  • 1
  • 19
  • 21

2 Answers2

0

You may be able to find some help with this previous question:

How to use bash/expect to check if an SSH login works

Depending on your situation you might also to execute an remote ssh command and wait for positive feedback.

See:

How to use SSH to run a shell script on a remote machine?

Community
  • 1
  • 1
bakercp
  • 924
  • 7
  • 12
0

you should have a look at ssh ProxyCommands that lets you do indirect connects automatically. basically you put the following in you .ssh/config

Host gateway1
  # nichts

Host gateway2
  ProxyCommand ssh -q gateway1 nc -q0 gateway2 22

Host targethost
  ProxyCommand ssh -q gateway2 nc -q0 targethost 22

and then you can run ssh targethost successfully even if targethost is not reachable directly. you can read more about this e.g. here http://sshmenu.sourceforge.net/articles/transparent-mulithop.html

mnagel
  • 6,729
  • 4
  • 31
  • 66