ruby net-ssh calling bash script with interactive prompts

前端 未结 1 1755
孤独总比滥情好
孤独总比滥情好 2021-01-28 23:29

I have a problem that I hope you can help me with

I’m trying to use ruby to ssh onto a machine and run a bash script, this part is fairly easy but the bash script requir

1条回答
  •  醉话见心
    2021-01-29 00:07

    managed to fix this by using the channel function, here's the method I use now

    def connect(host,command)
    
      require 'rubygems'
      require 'net/ssh'
    
      user = LocalConfig::SSH_DETAILS[:user]
      pass = LocalConfig::SSH_DETAILS[:pass
    
        o = ""
        Net::SSH.start(host, user, :password => pass, :paranoid => false, :auth_methods => ['password'], :timeout => 30 )do |ssh |
          channel = ssh.open_channel do |ch|
        ch.exec(command) do |ch2, success|
          ch2.send_data "myUserName\n"
          ch2.send_data "mPassWord\n"
    
          ch.on_data do |ch2, data|
            o += data
          end
        end
          end
          channel.wait
          return o.to_s
        end
    end
    

    0 讨论(0)
提交回复
热议问题