Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

undefined method `chomp' for nil:NilClass #424

Closed
tfluehmann opened this issue Aug 15, 2016 · 4 comments
Closed

undefined method `chomp' for nil:NilClass #424

tfluehmann opened this issue Aug 15, 2016 · 4 comments

Comments

@tfluehmann
Copy link
Contributor

Hello everyone

We have an issue every 200th time when we login into a cisco ios machine.
We get the following error:
undefined method `chomp' for nil:NilClass

["/home/safe/rails_projects/safe4/.bundle/ruby/2.2.0/gems/net-ssh-3.0.2/lib/net/ssh/prompt.rb:73:in `prompt'"
"/home/safe/rails_projects/safe4/.bundle/ruby/2.2.0/gems/net-ssh-3.0.2/lib/net/ssh/authentication/methods/password.rb:57:in `ask_password'"
"/home/safe/rails_projects/safe4/.bundle/ruby/2.2.0/gems/net-ssh-3.0.2/lib/net/ssh/authentication/methods/password.rb:22:in `authenticate'"
"/home/safe/rails_projects/safe4/.bundle/ruby/2.2.0/gems/net-ssh-3.0.2/lib/net/ssh/authentication/session.rb:79:in `block in authenticate'"
"/home/safe/rails_projects/safe4/.bundle/ruby/2.2.0/gems/net-ssh-3.0.2/lib/net/ssh/authentication/session.rb:66:in `each'"
"/home/safe/rails_projects/safe4/.bundle/ruby/2.2.0/gems/net-ssh-3.0.2/lib/net/ssh/authentication/session.rb:66:in `authenticate'"
"/home/safe/rails_projects/safe4/.bundle/ruby/2.2.0/gems/net-ssh-3.0.2/lib/net/ssh.rb:229:in `start'"

We are using net-ssh 3.0.2 and ruby 2.3.1.
It looks like the machine sends EOF and gets returns nil. Is it possible to implement a rescue in the prompt method?

      def prompt(prompt, echo=true)
        @seen_warning ||= false
        if !echo && !@seen_warning
          $stderr.puts "Text will be echoed in the clear. Please install the HighLine or Termios libraries to suppress echoed text."
          @seen_warning = true
        end

        $stdout.print(prompt)
        $stdout.flush
       $stdin.gets.chomp
end

Kind Regards
tfluehmann

@mfazekas
Copy link
Collaborator

See #366 #234

Can you detail the usecase? Do you use password auth? Or do you have key auth? I assume you have public key auth which fails in every 100th cases and falls back to password auth that tries to ask for password which fails because the stdin is redirected.

The error suggest that the app is non interactive and your stdin is redirected. You should be using the non_interactive option, so that no prompt will be asked.

@tfluehmann
Copy link
Contributor Author

@mfazekas
We are using passwort authentication. We have currently no options set.
I will implement the non_interactive and test it for a while.

I haven't found the other issues while my research, I think can close this afterwards.

Thank you.

@mfazekas
Copy link
Collaborator

If you use non_interactive that means it will not ask for password, so might not be suitable for you

$stdin.gets only returns nil for end of file. Is this an interactive prompt? Is the user pressing ctrl+D?

@tfluehmann
Copy link
Contributor Author

I can't say to be honest. But I exepect it to be, see here: http://www.cisco.com/c/en/us/td/docs/ios-xml/ios/sec_usr_ssh/configuration/15-e/sec-usr-ssh-15-e-book/sec-secure-shell-v2.html#GUID-5A1D0EE5-15BE-4F84-973F-E73FF4628C1A

We just ran into that case every few days but the script is running every 10 minutes. So I will be able to say if it fixed it probably in a few days.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants