SSH execute remote command (with jump)

Hi all,
I am facing the following issue:

Host A should execute a remote command (say pwd) on host B2.
B2 is not directly reacheable but you have to connect from a to B1, then from B1 you can execute the command ssh user@B2 pwd.
B1 and B2 are directly connected:

A => B1 => B2
| ^
|____pwd__|

Is there a way to use ssh from host A + single command to do the work?

Thank you very much for help.

Evan

Maybe this works:

#!/usr/bin/expect
spawn ssh usr1@IP_of_B1 ssh usr2@IP_of_B2 pwd #pwd is the command you wanna execute on B2
expect "password"
send "passowrd_of_usr1\n"
expect "password"
send "passowrd_of_usr2\n"
expect eof
exit

set ssh tunnel on server A1.

ssh -f userB1@B1 -L 2000:B2:22 -N

then you can run :

ssh -P 2000 localhost pwd

It will show B2 status

OR

On serverA

ssh userB1@B1 "ssh userB2@B2 pwd"

need keyless

Hi vistastar,
thank you for your suggestion.

Since I can't use expect I just tried to ssh twice:
ssh userB1@B1 "ssh userB2@B2 pwd"
I didn't thought about this solution, but it make sense (THANKS!!).

It works fine :wink:

Thanks again,
Evan