SSH prompt before first command with ruby and Net::SSH

Discussion in 'Ruby' started by umamahe1007, May 15, 2014.

  1. umamahe1007

    umamahe1007 Guest

    1 down vote favorite


    I'm trying to connect, using Net::SSH, to a server that immediately after login with admin credentials and executes a script that requires input as 'Yes' or 'No' , based on the input next command will excute in the terminal afterwards.

    My problem is that, although I am able to connect, I can able to send "Yes\n" to the server but the loop doesn't ends

    require 'net/ssh'
    Net::SSH.start(Host, 'root',:port => "26", :password =>
    "pass") do |ssh|
    ssh.open_channel do |channel|
    channel.request_pty:)term => "xterm") do |ch, success|
    if success
    puts "pty successfully obtained"
    ch.send_channel_request "shell" do |ch, success|
    if success
    ch.send_data("su admin\n")
    ch.send_data("command\n")
    ch.on_process do |data|
    ch.send_data("yes\n")
    ch.send_data("command\n")
    end
    else
    puts "could not start user shell"
    end
    end
    else
    puts "could not obtain pty"
    end
    end

    end
    ssh.loop
    end
     
    umamahe1007, May 15, 2014
    #1
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.