U
umamahe1007
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',ort => "26", assword =>
"pass") do |ssh|
ssh.open_channel do |channel|
channel.request_ptyterm => "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
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',ort => "26", assword =>
"pass") do |ssh|
ssh.open_channel do |channel|
channel.request_ptyterm => "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