2

For a specific bash command when I execute it locally after completion I got the shell free but when I execute remotely the shell hangs like that:

[user@host ~]$ ruby bin/remote_control.rb  server start_server1
Running /home/server_manager.sh start_server ... wait

[]

When I use ruby and NET::SSH to call remotely this command and it's necessary to press ctrl+C to to get the shell prompt available again and press enter doesn't work.

Again the remote script/command /home/server_manager.sh doesn't has this behavior when called locally

For get free the terminal the script has this syntax:

I'm trying to execute in backgroud
`commmand &` 2>&1 | echo "\n"

And the ruby code bellow is used for calling the script above:

Net::SSH.start(@hostname, @username, :password => @password) do |ssh|

  channel = ssh.open_channel do |ch|
     ch.exec @cmd do |ch, success|
        raise "Could not execute command: #{cmd}" unless success

        ch.on_data do |c, data|            
           begin
              if !data.nil?  then
                  print data
              else 
                  exit
              end        
           rescue SystemExit
              puts "Rescued a SystemExit exception"
           end               
        end

        ch.on_extended_data do |c, type, data|
           begin
              if !data.nil?  then
                  print data
              else 
                  exit
              end        
           rescue SystemExit
              puts "Rescued a SystemExit exception"
           end   
        end

        ch.on_eof do |ch|
           puts "Cmd finished with success: #{@cmd}"
           $LOG.info("Cmd finished with success: #{@cmd}")
        end
        ch.on_close { puts "Done!" }
     end
  end
 channel.wait

 ssh.loop
end

But I haven't success until now. What I need to add to this code to always have the shell free.

4

0 回答 0