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

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',: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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top