duke-automation / net-ssh-telnet

A ruby module to provide a simple send/expect interface over SSH with an API almost identical to Net::Telnet. Ideally it should be a drop in replacement. Please see Net::Telnet for main documentation (included with ruby stdlib).
7 stars 4 forks source link

Host not responding to commands #2

Closed abadfish closed 7 years ago

abadfish commented 7 years ago

I posted this first in the original net-ssh-telnet repo and the owner referred me to this one. Hoping someone has some insight.

My logfile says I get to a place where the shell says "Please press return to continue" after logging in. I've tried using #waitfor(/Please press return to continue/) and #cmd(" ") or #cmd("\n") and it still hangs. Anyone have any idea how to better send the command?

ssh = Net::SSH.start(nil, nil,
                     :host_name => @hostname,
                     :user => @username,
                     :password => "@password,
                     :verbose => :debug
                     )
    @apl= Net::SSH::Telnet::new(
                    "Session" => ssh,
                    "Dump_log" => @dumpf,
                    "Output_log" => @logf,
                    "Binmode" => true,
                    "Timeout" => 20,
                    "Terminator" => "\r"
                    )
    @apl.cmd("\n")
seandilda commented 7 years ago

Does the 'Please press return to continue' happen before or after the '@apl.cmd("\n")' line?

abadfish commented 7 years ago

It happens before.. I have also tried:

@apl.waitfor(/Please press return to continue/) do |apl|
      apl.cmd( " ", /WHICH OPTION/)
      apl.cmd("EXP", /WHICH FUNCTION/)
    end
seandilda commented 7 years ago

Gotcha. The problem you're hitting is that Net::SSH::Telnet::new has a waitfor embedded in it with the default prompt. You'll need to do something like:

@apl = Net::SSH::Telnet.new(
                              ...
                              'Prompt' => /Please press return to continue/,
)
@apl.prompt = /[$%#>] \z/n # This is the default prompt used by Net::SSH::Telnet
@apl.cmd(<your first command>)

To do this, you'll need to switch from the net-ssh-telnet gem to the net-ssh-telnet2 gem, and install at least version 0.2.0

Please let me know if this works for you.

abadfish commented 7 years ago

Ok. I uninstalled net-ssh-telnet and installed net-ssh-telnet2. When requiring the gem in the file do I still require 'net/ssh/telnet' ?

seandilda commented 7 years ago

That's right, its still a require of 'net/ssh/telnet' and is a drop in replacement for net-ssh-telnet.

I double checked my existing code, the snippet above should be something closer to:

@apl = Net::SSH::Telnet.new(
  ...,
  'Prompt' => /Please press return to continue/,
)
@apl.prompt = /[$%#>] \z/n # This is the default prompt used by Net::SSH::Telnet
@apl.cmd('')
@apl.cmd(<your first command>)
@apl.cmd(<your first command>)
abadfish commented 7 years ago

This is what I have now and it's still timing out:

    @apl= Net::SSH::Telnet::new(
                    "Session" => ssh,
                    "Dump_log" => @dumpf,
                    "Output_log" => @logf,
                    "Timeout" => 20,
                    "Prompt" => /Please press return to continue/
                    )
    @apl.prompt = /[$%#>] \z/n

    @apl.cmd(" ")
    @apl.cmd("EXP")
seandilda commented 7 years ago

Would you mind sending me a copy of your log file (with any sensitive data removed)? Here or email works.

abadfish commented 7 years ago

Last unsuccessful login: Mon Apr 17 10:48:48 2017 on ssh from XXX.XXX.XXX.XXX Last login: Tue Apr 18 13:04:14 2017 on ftp from ::ffff:XXX.XXX.XXX.XXX**


Dyalog APL/S-64 Version 12.1.0 Classic For IBM RISC System/6000 Created: May 29 2015 at 10:54:54 Copyright (c) Dyalog Limited 1982-2015 (B[?7l[?1l(B(BDyalog APL/S-64 Version 12.1.0Classic EditionTue Apr 18 13:04:19 2017 /sa/Prgs/PA12 saved Fri Dec 4 20:40:11 2009 PA12 M0 Ins(BPORTVUE - 04/18/17 1:04 P.M.(WA=450617296 )(BSETACCT(B****Sensitive information removed....(0lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq(B (0x(B System Tip for the day- (0x(B ... (0x(B (0mqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq(B PA12 M0 Ins(B GO(B No outstanding news available(BPlease press return to continuePA12 M0 Ins(B PV

abadfish commented 7 years ago

And the end of the dump log:

1b 5b 32  34 3b 38 30  48 0d 0a 1b  5b 32 32 3b  B.[24;80H...[22;
< 0x001f0: 31 48 1b 5b  32 34 3b 36  38 48 1b 5b  30 6d 50 41  1H.[24;68H.[0mPA
< 0x00200: 31 32 20 4d  30 20 20 49  6e 73                     12 M0  Ins

< 0x00000: 1b 28 42 1b  5b 32 33 3b  31 48 1b 5b  4b 1b 5b 32  .(B.[23;1H.[K.[2
< 0x00010: 34 3b 31 48  1b 5b 4b 1b  5b 32 34 3b  38 30 48 0d  4;1H.[K.[24;80H.
< 0x00020: 0a 1b 5b 32  32 3b 31 48  1b 5b 30 6d  47 4f        ..[22;1H.[0mGO

< 0x00000: 1b 28 42 1b  5b 32 34 3b  38 30 48 0d  0a 1b 5b 32  .(B.[24;80H...[2
< 0x00010: 32 3b 31 48  4e 6f 20 6f  75 74 73 74  61 6e 64 69  2;1HNo outstandi
< 0x00020: 6e 67 20 6e  65 77 73 20  61 76 61 69  6c 61 62 6c  ng news availabl
< 0x00030: 65 1b 28 42  1b 5b 32 33  3b 31 48 50  6c 65 61 73  e.(B.[23;1HPleas
< 0x00040: 65 20 70 72  65 73 73 20  72 65 74 75  72 6e 20 74  e press return t
< 0x00050: 6f 20 63 6f  6e 74 69 6e  75 65 1b 5b  32 34 3b 36  o continue.[24;6
< 0x00060: 38 48 1b 5b  30 6d 50 41  31 32 20 4d  30 20 20 49  8H.[0mPA12 M0  I
< 0x00070: 6e 73 1b 28  42 1b 5b 32  34 3b 36 38  48 20 20 50  ns.(B.[24;68H  P
< 0x00080: 56 1b 5b 32  33 3b 33 33  48       
seandilda commented 7 years ago

Closing this - for anyone finding this later, the fix involved setting the 'Terminator' option to "\r" when initializing Net::SSH::Telnet as that's what AIX was wanting instead of "\n"