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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run Commands on a system 1 hop away 2

Status
Not open for further replies.

jdespres

MIS
Aug 4, 1999
230
US
I would like to run unix commands on a system that is one hop away. That is I have to ssh to the jump box then ssh to the box in question in order to run commands on that system....

Thanks.....

Joe Despres
 
And what is the problem ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
No real problem.....
.
Except for laziness!
.
Would like to skip a step in monitoring and dealing with a solaris system

Joe Despres
 
Use autoexpect or write an expect script to automate the
first hop interaction.
Code:
#!/usr/bin/tclsh
package require Expect
set host1 "host1"
set host2 "host2"
set prompt ".*@.*"
set timeout 20
#exp_internal 1
log_user 0


spawn -noecho ssh $host1

                        expect {

			         -re ".*asswo.*" {
				                send_user "At spawn id = $spawn_id: $expect_out(buffer) "
						stty -echo
						set password [gets stdin]
						send "$password\r\n"
						stty echo
						expect -re $prompt {
						                   send "\nssh $host2\r\n"
								   interact
						}
				 }


				 eof {send_user "\nConnection abnormally closed\n"}
				 timeout {send_user "\nConnection timeout\n"}
		        }
 
Put this in a shell script:
Code:
ssh firsthop.hostname "ssh secondhop.hostname \"$@\""

If your keys are set up correctly you can run it with no passwords.
 
Here's my output when I tried that command line...

$ ssh root@mnvbk01 "ssh root@wnd4u02a \"$@\""
root@mnvbk01's password:
Pseudo-terminal will not be allocated because stdin is not a terminal.

You have no controlling tty. Cannot read passphrase.
 
I added "-t" to the first ssh command and it worked!

Thanks!!!
 
Take a look at the -t option in the ssh man page.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
OOps, seems we posted at same time.
Glad you achieved your goal.
 
I wonder.............

Could I squeeze another hop in there?
 
You have to be well confident with the shell(s) quoting mechanism ...

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top