Discussion:
[rancid] cygwin + long hostname = clogin hang
Lee
2010-08-23 21:44:33 UTC
Permalink
clogin hangs when I use it from cygwin to ssh into a cisco switch with
a long hostname.

It looks like a bug in cygwin expect causes the timeout. The
expect {
-re $reprompt { }
at line 611 fails if I've got a long hostname configured on the cisco switch:

expect: does "2ndFloorLibrarySW>" (spawn_id 4) match regular
expression "2ndFloorLib([^#>\r\n]+)?[#>](\([^)\r\n]+\))?"? no
"[\n\r]+"? no
expect: timed out

If I change the pattern to include more of the hostname the match works:
expect: does "2ndFloorLibrarySW>" (spawn_id 4) match regular
expression "2ndFloorLibrar([^#>\r\n]+)?[#>](\([^)\r\n]+\))?"? yes
expect: set expect_out(0,string) "2ndFloorLibrarySW>"
expect: set expect_out(1,string) "ySW"
expect: set expect_out(spawn_id) "4"
expect: set expect_out(buffer) "2ndFloorLibrarySW>"

so my work-around is to use up to 21 characters of the hostname in
reprompt. Line 610 changes from
regsub -all {^(.{1,11}).*([#>])$} $prompt
{\1([^#>\r\n]+)?[#>](\\([^)\\r\\n]+\\))?} reprompt
to
regsub -all {^(.{1,21}).*([#>])$} $prompt
{\1([^#>\r\n]+)?[#>](\\([^)\\r\\n]+\\))?} reprompt


And then at clogin line 423, if a timeout happens clogin hangs until I
open task manager and kill the ssh process (<ctrl>C in the terminal
window doesn't kill it). The 'catch{close}; catch{wait};' doesn't end
the ssh session. Adding a 'send "exit\r"' fixes the hang for me:

# This helps cleanup each expect clause.
expect_after {
timeout {
send_user "\nError: TIMEOUT reached\n"
send "exit\r" ;# --LR--
catch {close}; catch {wait};
if { $in_proc} {
return 1
} else {
continue
}

Lee
john heasley
2010-08-24 05:25:17 UTC
Permalink
Post by Lee
clogin hangs when I use it from cygwin to ssh into a cisco switch with
a long hostname.
It looks like a bug in cygwin expect causes the timeout. The
expect {
-re $reprompt { }
likely means that the regex library is broken. the length is not entirely
arbitrary.
Post by Lee
expect: does "2ndFloorLibrarySW>" (spawn_id 4) match regular
expression "2ndFloorLib([^#>\r\n]+)?[#>](\([^)\r\n]+\))?"? no
"[\n\r]+"? no
expect: timed out
expect: does "2ndFloorLibrarySW>" (spawn_id 4) match regular
expression "2ndFloorLibrar([^#>\r\n]+)?[#>](\([^)\r\n]+\))?"? yes
expect: set expect_out(0,string) "2ndFloorLibrarySW>"
expect: set expect_out(1,string) "ySW"
expect: set expect_out(spawn_id) "4"
expect: set expect_out(buffer) "2ndFloorLibrarySW>"
so my work-around is to use up to 21 characters of the hostname in
reprompt. Line 610 changes from
regsub -all {^(.{1,11}).*([#>])$} $prompt
{\1([^#>\r\n]+)?[#>](\\([^)\\r\\n]+\\))?} reprompt
to
regsub -all {^(.{1,21}).*([#>])$} $prompt
{\1([^#>\r\n]+)?[#>](\\([^)\\r\\n]+\\))?} reprompt
And then at clogin line 423, if a timeout happens clogin hangs until I
open task manager and kill the ssh process (<ctrl>C in the terminal
window doesn't kill it). The 'catch{close}; catch{wait};' doesn't end
maybe try the linux/solaris expect patches.

you could also try a unix box
Lee
2010-08-27 14:06:25 UTC
Permalink
Post by john heasley
Post by Lee
clogin hangs when I use it from cygwin to ssh into a cisco switch with
a long hostname.
It looks like a bug in cygwin expect causes the timeout. The
expect {
-re $reprompt { }
likely means that the regex library is broken. the length is not entirely
arbitrary.
Just out of curiosity - what made you pick up to the first 11 chars of
the prompt?

<.. snip regex problem description ..>
Post by john heasley
Post by Lee
And then at clogin line 423, if a timeout happens clogin hangs until I
open task manager and kill the ssh process (<ctrl>C in the terminal
window doesn't kill it). The 'catch{close}; catch{wait};' doesn't end
maybe try the linux/solaris expect patches.
Is there some situation where sending "exit\r" after getting a timeout
would be a bad idea?

I found an expect doc that said 'close' was supposed to close an open
connection, but it clearly doesn't for ssh with cygwin expect.
Changing the length of reprompt is a cygwin work-around (and if anyone
else runs into the same problem, the work-around is in the archives
now :), but is sending an exit after getting a timeout a cygwin
work-around or a not-so-bad idea for general use?
Post by john heasley
you could also try a unix box
$WORK can be a bit strange. I've got PC admin privs, in part, to
'evaluate software' but I was told that I couldn't install this
software on a linux box until I got the software approved. *sigh*

Thanks,
Lee
john heasley
2010-08-27 16:00:12 UTC
Permalink
Post by Lee
Post by john heasley
Post by Lee
clogin hangs when I use it from cygwin to ssh into a cisco switch with
a long hostname.
It looks like a bug in cygwin expect causes the timeout. The
expect {
-re $reprompt { }
likely means that the regex library is broken. the length is not entirely
arbitrary.
Just out of curiosity - what made you pick up to the first 11 chars of
the prompt?
i do not remember exactly how I arrived at 11, but it is a balance of
being as long as possible to be unique and maintaining the match when in
configure mode (see -x and -s).
Post by Lee
<.. snip regex problem description ..>
Post by john heasley
Post by Lee
And then at clogin line 423, if a timeout happens clogin hangs until I
open task manager and kill the ssh process (<ctrl>C in the terminal
window doesn't kill it). The 'catch{close}; catch{wait};' doesn't end
maybe try the linux/solaris expect patches.
Is there some situation where sending "exit\r" after getting a timeout
would be a bad idea?
you may not have a file descriptor to write to, but otherwise i doubt it.
its as easy to just close the connection and it then the script does not
need to consider state of the device, though it means that it relies upon
the device to clean-up.

Loading...