LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-20-2015, 06:04 PM   #1
nitrohuffer2001
Member
 
Registered: Apr 2006
Posts: 165

Rep: Reputation: 19
expect + ssh through proxy host weirdness


Hi,

So I have this command:
Code:
ssh -o User=myname -o ProxyCommand="ssh -W %h:%p myname@my-proxy-server" -L 1111:localhost:22 my-destination-server
This works great, but......when I try to put it into an expect script like so:

Code:
spawn ssh -o User=myname -o ProxyCommand="ssh -W \%h\:\%p myname@my-proxy-server" -L 1111:localhost:22 my-destination-server
I get the following error:

Code:
MacBook-Pro:bin myname$ ./myscript 
Script configuration:	username = 	bastion = 	host = 	appuser = 
spawn ssh -o User=myname -o ProxyCommand="ssh -W %h:%p myname@my-proxy-server" -L 1111:localhost:22 my-destination-server
Bad stdio forwarding specification '%h:%p'
send: spawn id exp7 not open
    while executing
"send "$password\n""
    (file "./myscript" line 31)
    
This is line 31: send "$password\n"
Whole script for reference:

Code:
#!/usr/bin/expect
## This script ignores 

trap {
 set rows [stty rows]
 set cols [stty columns]
 stty rows $rows columns $cols < $spawn_out(slave,name)
} WINCH

set timeout -1
set SSH_OPT "-o PubkeyAuthentication=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no"
set username [lindex $argv 0]
set bastion [lindex $argv 1]
set host [lindex $argv 2]
set appuser [lindex $argv 3]
set passwordfile [open "~/.ssh/password" r]
set password [read $passwordfile]
close $passwordfile

send "Script configuration:\tusername = $username\tproxy = $proxy\thost = $host\tappuser = $appuser\n"

#works out side of script
#spawn ssh -o User=myname -o ProxyCommand="ssh -W \%h\:\%p myname@my-proxy-server" -L 1111:localhost:22 my-destination-server

# Throws error
#spawn ssh -o User="$username" -o ProxyCommand="ssh -W \%h\:\%p "$username\@$my-proxy-server" -L 1111:localhost:22 my-destination-server

#spawn ssh -o PubkeyAuthentication=no -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no "$username\@$my-proxy-server"

expect "password:"
send "$password\n"

interact
Any ideas?

Thanks.
 
Old 07-24-2015, 03:09 PM   #2
mpapet
Member
 
Registered: Nov 2003
Location: Los Angeles
Distribution: debian
Posts: 548

Rep: Reputation: 72
Just a guess here, but it works "outside" the script because you are using the shell and all the extras it provides.

I would turn it into a bash script, or whatever shell scripting apple provides.
 
Old 07-24-2015, 03:52 PM   #3
michaelk
Moderator
 
Registered: Aug 2002
Posts: 25,703

Rep: Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896Reputation: 5896
The quotes should be around the entire ProxyCommand option. I have not checked the rest of your code.

Code:
spawn ssh -o User=myname -o "ProxyCommand=ssh -W %h:%p myname@my-proxy-server" -L 1111:localhost:22 my-destination-server
 
1 members found this post helpful.
Old 08-13-2015, 08:17 PM   #4
kmhuntly
Member
 
Registered: Mar 2015
Location: Cheektowaga, NY
Distribution: ArchLinux
Posts: 34

Rep: Reputation: 7
The %'s shouldn't need to be escaped
 
Old 08-18-2015, 06:45 PM   #5
nitrohuffer2001
Member
 
Registered: Apr 2006
Posts: 165

Original Poster
Rep: Reputation: 19
expect + ssh through proxy host weirdness SOLVED

Adding the quotes around the entire ProxyCommand option solved the problem.

Thanks
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to connect a remote host via ssh behind proxy swaggerlee Linux - Newbie 29 06-07-2013 03:40 AM
Connect to a proxy through a middle host with a ssh tunnel iacchi Linux - Networking 3 02-16-2012 12:02 PM
Help: Weirdness with ssh/pam when trying to ssh in Nabana Linux - Security 1 04-01-2010 08:17 PM
Ubuntu Host Virtualbox guest Networking weirdness ddales Linux - Networking 0 01-20-2008 02:24 PM
host file weirdness EdR Red Hat 1 09-27-2005 06:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:36 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration