SSH execute remote command (with jump)


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting SSH execute remote command (with jump)
# 1  
Old 09-20-2010
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
# 2  
Old 09-21-2010
Maybe this works:

Code:
#!/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


Last edited by vistastar; 09-21-2010 at 05:49 AM..
# 3  
Old 09-21-2010
set ssh tunnel on server A1.

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

then you can run :

Code:
ssh -P 2000 localhost pwd

It will show B2 status

OR

On serverA
Code:
ssh userB1@B1 "ssh userB2@B2 pwd"

need keyless
# 4  
Old 09-21-2010
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 Smilie

Thanks again,
Evan
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to execute setDomainEnv.sh in wblogic via ssh on remote server in shell script?

How to execute setDomainEnv.sh in wblogic via ssh on remote server in shell script we execute setDomainEnv.sh manually as . ./setDomainEnv.sh from its location ie /opt/SP/users/domian/bin" My approach is not working. Please advise. #!/bin/bash set -x base="/opt/SP/users/d1/bin"... (5 Replies)
Discussion started by: abhaydas
5 Replies

2. Shell Programming and Scripting

Execute ssh command with additional terminal command to any remote user not working script

Hello i am having an issue with bash script and this is the code now=$(cat hosts1.txt | awk '{print $2;}') while read n ;do ssh root@$now 'useradd test1; echo -e "test1\ntest1" | passwd test1 && echo "test1 ALL=(ALL:ALL) ALL" >> /etc/sudoers' When i execute only part with cat, it... (8 Replies)
Discussion started by: tomislav91
8 Replies

3. Shell Programming and Scripting

Execute command on remote host via ssh

How should i make the following code working #!/bin/bash INPUTFILE="test.txt" while read STRING; do IP=`host -t A $STRING | awk '{print $NF}'` HOSTNAME=`ssh -oPasswordAuthentication=no -oStrictHostKeyChecking=no $IP "hostname"` echo $HOSTNAME > out.txt done < $INPUTFILE At this moment while... (3 Replies)
Discussion started by: urello
3 Replies

4. Shell Programming and Scripting

Shell script help to execute ssh remote commands

Hi, The below command is not giving me the count , Can somebody help me in re-writing this pls . Proc_Exist=`ssh -q -o "BatchMode=yes" -o "PasswordAuthentication=no" $OAUSER@${Primary_Node} ps -ef | grep -v grep | grep "${ICM_Proc}" |wc -l ` Also the same problem with below... (13 Replies)
Discussion started by: Y.balakrishna
13 Replies

5. Shell Programming and Scripting

bash script to execute a command remote servers using ssh

Hello, I am running into few issues, please suggest me what I am missing. I am running this script on a linux host. Main idea of this script is to, login to each host via ssh and get uid of user, service user that I trying to run this script, has already deployed ssh keys and provide sudo... (8 Replies)
Discussion started by: bobby320
8 Replies

6. Shell Programming and Scripting

Using ssh to execute a remote script in the background

Help please!! I want to use ssh to execute a remote exe and while it's running I want to query for the process ID of the exe (2 different ssh commands) 1. sshpass -p "<passwd>" ssh -f -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@<ipaddress> nohup /tmp/mmds_asyn & 2.... (0 Replies)
Discussion started by: rvompoluTMW
0 Replies

7. Shell Programming and Scripting

ssh to remote host and execute command

Hi, could anyone please tell me how to ssh to remote host foo and execute command on it and print the result on local host? Thanks, Paresh (1 Reply)
Discussion started by: masaniparesh
1 Replies

8. Shell Programming and Scripting

How to execute remote ssh command - Perl and CGI

Hi, I am having nightmare issue-ing remote ssh command from a CGI perl script. It just won't run on debug message: It says permission denied. Can I even do this? as the apache server running under DAEMON account probably can't execute it? Is this the case of what's going on? Here is my... (3 Replies)
Discussion started by: Dabheeruz
3 Replies

9. SCO

Execute command in remote

Hi, How to execute unix commands in remote unix servers? Thanks, Pintu (2 Replies)
Discussion started by: pintupatro
2 Replies

10. UNIX for Dummies Questions & Answers

execute a command in remote

how exec a command (ex. a cut or grep ) in anoter pc i have IP address, login and password. (another account of unix system) what's the sintax of command ??? es. my ip is 192.xx.xx.xx i make a exec of "ls" redirect in outpu file (> "file) in another pc ( ip 192.44.55.2xxx) (3 Replies)
Discussion started by: ZINGARO
3 Replies
Login or Register to Ask a Question